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: set moduleResolution to nodenext for nextjs tsconfig #27

Conversation

cprussin
Copy link
Owner

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2023

🦋 Changeset detected

Latest commit: c747b54

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cprussin/tsconfig Major

Not sure what this means? Click here to learn what changesets are.

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

@cprussin cprussin force-pushed the cprussin/remove-moduleResolution-node-from-nextjs-tsconfig branch from 6825bdf to c747b54 Compare August 18, 2023 05:18
@cprussin
Copy link
Owner Author

Future notes to self:

As it turns out, there are still some issues with nodenext in a bundled environment.

The core of the problem is basically:

  • Bundlers (including swc) have an interop mode where they hoist exports under the .default key up to the root of the module if the .__esModule property is set on a cjs module.
  • Typescript follows Node's resolution strategy when using nodenext (that's the purpose of the setting after all), and in particular this means it does not hoist regardless of the presence of .__esModule.
  • Next.js doesn't expose any way to set swc options, or any way to set noInterop to disable the interop behavior.

As a result, there's a bunch of places you need to add .default to make typescript work, but at runtime the hoisting makes the .default break.

Possible fixes here could be:

  • Next.js exposes option to set swc's noInterop option (most realistic)
  • Upstream modules distribute ESM (and declare themselves so -- if modules don't set "type": "module" in their package.json then we'll still have issues) or avoid default exports (most ideal but least realistic)
  • Typescript exposes some option to enable a partial nodenext that enforces extensions & full paths but still enables interop (least ideal)

@cprussin cprussin closed this Aug 20, 2023
@cprussin cprussin deleted the cprussin/remove-moduleResolution-node-from-nextjs-tsconfig branch August 20, 2023 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant