Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imports for moduleResolution: nodenext TS users (v4) #6731

Merged
merged 8 commits into from
Aug 24, 2022

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Jul 25, 2022

When installing @apollo/server v4 in a TS project using "moduleResolution": "nodenext", TS throws a bunch of errors about how Apollo Server's imports need to use extensions. Specifically, we omitted extensions from all type-only imports since they didn't seem to be needed, but it's not hurting anything to add them and some use cases require it.

Fixes #6730

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

⚠️ No Changeset found

Latest commit: fcb0295

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jul 25, 2022

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit 8e48da7
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/63056c9911713c00089802d3
😎 Deploy Preview https://deploy-preview-6731--apollo-server-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 25, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8e48da7:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration
dazzling-star-sxnxmh Issue #6730
Apollo Server Issue #6730

@trevor-scheer
Copy link
Member Author

I'm able to reliably reproduce and then resolve the issue via this codesandbox:

https://codesandbox.io/s/hungry-bird-mzs69d

There seems to be some package caching, so it needs a thorough clean to reproduce.

  1. install @apollo/[email protected]
  2. if builds don't fail with above mentioned errors, delete dist, yarn.lock, and restart container
  3. rebuild should show TS errors
  4. install @apollo/server codesandbox build from this PR via: https://pkg.csb.dev/apollographql/apollo-server/commit/a61bb855/@apollo/server
  5. TS errors are resolved

@trevor-scheer trevor-scheer marked this pull request as ready for review July 25, 2022 23:26
@trevor-scheer trevor-scheer requested a review from glasser July 25, 2022 23:26
@glasser
Copy link
Member

glasser commented Jul 26, 2022

can you smoke-test it? (and ideally eslint but ISTR that wasn't possible)

@trevor-scheer
Copy link
Member Author

@glasser I tried to reproduce this locally by cherry picking the new smoke test fcb0295 commit onto version-4 - test passes. So...the test I have so far is missing something that caused the original problem.

Needs more investigation, and possibly a more complex configuration than our current smoke tests use. i.e. I think I need a "module": ... or "type": "module" field in package.json...node needs to know it's using ESM.

@trevor-scheer trevor-scheer force-pushed the trevor/fix-imports-v4 branch 4 times, most recently from c69326b to e56d168 Compare August 23, 2022 20:43
@trevor-scheer trevor-scheer force-pushed the trevor/fix-imports-v4 branch from e56d168 to 1a414a4 Compare August 23, 2022 20:47
@trevor-scheer
Copy link
Member Author

My previous comment was correct - the package.json "type": "module" was the crux of this reproduction. To the point where the script running tsc actually has to be in the correct directory (adjacent to the relevant package.json) for this test to work correctly!

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bummer that AFAIK we can't make eslint check this (since that's a lot faster than smoke-test). import-js/eslint-plugin-import#2270 ...

.changeset/old-papayas-switch.md Outdated Show resolved Hide resolved
"type": "module",
"module": "./dist/smoke-test.js",
"dependencies": {
"@apollo/server": "../node_modules/@apollo/server",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the smoketests install a built tarball — is that OK? or is this reading from inside smoke-test anyway i guess... huh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the reproduction a bit, and you're right that it's just looking up.
cee95bb

@trevor-scheer trevor-scheer requested a review from glasser August 23, 2022 23:33
@trevor-scheer trevor-scheer changed the title Fix imports for nodenext TS users (v4) Fix imports for moduleResolution: nodenext TS users (v4) Aug 24, 2022
@trevor-scheer trevor-scheer merged commit 9fc23f7 into version-4 Aug 24, 2022
@trevor-scheer trevor-scheer deleted the trevor/fix-imports-v4 branch August 24, 2022 00:49
glasser pushed a commit that referenced this pull request Aug 25, 2022
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to version-4, this PR will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-4` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `version-4`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @apollo/[email protected]

### Patch Changes

-   Updated dependencies \[[`3320fee92`](3320fee), [`9fc23f799`](9fc23f7), [`2cab8f785`](2cab8f7)]:
    -   @apollo/[email protected]

## @apollo/[email protected]

### Patch Changes

-   [#6841](#6841) [`3320fee92`](3320fee) Thanks [@glasser](https://github.com/glasser)! - Upgrade @apollo/server-gateway-interface to have laxer definition of overallCachePolicy.


-   [#6731](#6731) [`9fc23f799`](9fc23f7) Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Use extensions for all imports to accommodate TS users using moduleResolution: "nodenext"


-   [#6846](#6846) [`2cab8f785`](2cab8f7) Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Ensure executionDidEnd hooks are only called once (when they throw)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request Oct 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants