-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(types): Fix module/moduleResolution options for TypeScript 5.2 #3251
Conversation
@@ -29,6 +29,7 @@ | |||
"main": "lib/index.js", | |||
"types": "lib/index.d.ts", | |||
"module": "lib/esm/index.js", | |||
"type": "commonjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t actually do anything as is, but having a placeholder makes using sed
a lot easier.
"esModuleInterop": true, | ||
"moduleResolution": "node16", | ||
"resolveJsonModule": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--module node16
implies all three of these things (though I had to add the explicit esModuleInterop
back; see the comment above)
@andrewbranch Thank you so much for the helping hand! |
Hi, coming here from Twitter discussion: https://twitter.com/atcb/status/1694038339312083055 I noted 3 things in that thread:
For the first one, you can see this report: Notice that there are errors in the commonjs section in the table, and the error varies depends on how the dependence are written. For the second one, it is relative minor as most of the time we will also define the For the third one, it is the case related to ESM package using |
👋 Hey, I work on the TypeScript team, and in 5.2 we’re planning to break your tsconfig, so I’m opening a PR to preemptively fix it. Specifically, we’re going to enforce that
module
andmoduleResolution
have to be set to the same value when either isnode16
ornodenext
.You’re currently using
moduleResolution: node16
in combination with bothmodule: commonjs
andmodule: esnext
in order to achieve dual module format emit with tsc. tsc isn’t really designed to work with those combinations, as explained in the afore-linked PR. Those limitations are why you were susceptible to issues like #2759 and need the eslint rule that enforces file extensions on import paths. Really, TypeScript should be doing that validation for you. (By the way, it looks like #2759 was never released, as the current release still has type resolution errors.)This PR makes a slight modification to your build scripts to ensure that tsc sees an accurate value for package.json
"type"
when compiling, which (with the right tsconfig settings) affects its type checking, module resolution, and emit to all be in sync. You might also be interested in tracking microsoft/TypeScript#54593 which, if we ever resolve, aims to make this kind of thing easier.Feel free to use this PR, edit it, or close it and do something different. Just wanted to give you a heads up and hopefully get you started down the right track.