-
Notifications
You must be signed in to change notification settings - Fork 12.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
Cannot import some packages when tsconfig.json specifies "module": "nodenext" #46770
Comments
Ok, so the The issue with (This whole thing is made more confusing by the fact that the editor glitches back and forth between CJS and ESM mode resolution because of #46373/#46396.) |
I'm also seeing this issue with Module resolution trace
It definitely finds the package, but for some reason is writing it off entirely as a valid resolution. |
I'm not certain, but I think I found the issue. TypeScript/src/compiler/moduleNameResolver.ts Lines 1675 to 1676 in 1cee973
This check (which is used in a few places) is causing For the purpose of debugging, I added I'm not certain what the purpose of |
This is directly controlled by the set With some more tracing I've isolated the branch causing the issue. TypeScript/src/compiler/moduleNameResolver.ts Lines 2020 to 2027 in 1cee973
And further TypeScript/src/compiler/moduleNameResolver.ts Lines 1675 to 1678 in 1cee973
The decision to not include |
I don't propose this as a "solution" (excuse the comments everywhere, I didn't clean up before committing) but this does fix the resolution issues for me. Silic0nS0ldier@dd8d8d9 |
See microsoft/TypeScript#46770 (comment) for detail, in `nodenext` module resolution it requires a full filename including extension
See microsoft/TypeScript#46770 (comment) for detail, in `nodenext` module resolution it requires a full filename including extension
See microsoft/TypeScript#46770 (comment) for detail, in `nodenext` module resolution it requires a full filename including extension
See microsoft/TypeScript#46770 (comment) for detail, in `nodenext` module resolution we need to specify `types` inside `exports` field.
… resolution See microsoft/TypeScript#46770 (comment) for detail, in `nodenext` module resolution it requires a `types` field in `exports` with full filename including extension
…le resolution (#1522) See [1] for detail, in `nodenext` module resolution it requires a `types` field in `exports` with full filename including extension. [1]: microsoft/TypeScript#46770 (comment) Reference: https://www.typescriptlang.org/tsconfig/#module
…le resolution (#4228) See [1] for detail, in `nodenext` module resolution it requires a `types` field in `exports` with full filename including extension. [1]: microsoft/TypeScript#46770 (comment)
…le resolution (#1522) See [1] for detail, in `nodenext` module resolution it requires a `types` field in `exports` with full filename including extension. [1]: microsoft/TypeScript#46770 (comment) Reference: https://www.typescriptlang.org/tsconfig/#module
declare function nullthrows(x: whatever): whatever;
declare namespace nullthrows {
export {nullthrows as default};
}
export = nullthrows; or something else to that effect. As for |
…le resolution (socketio#4228) See [1] for detail, in `nodenext` module resolution it requires a `types` field in `exports` with full filename including extension. [1]: microsoft/TypeScript#46770 (comment)
Bug Report
When a TypeScript project specifies
"module": "nodenext"
(or "node12") in tsconfig.json, tsc emits errors saying it can't find imported modules or that the exports aren't the right types.I've put together a demo that shows this with the "ip" and "nullthrows" packages. "ip" doesn't ship with TypeScript declarations and needs "@types/ip", while "nullthrows" comes with declarations. The precise errors are included below but in summary, tsc can't find "ip" and it thinks "nullthrows" is not callable despite the default export being a function.
Playing around, when I add
"type": "module"
to nullthrows's package.json, its error goes away. When I change ip's package.json from"main": "lib/ip"
to"main": "lib/ip.js"
, its issue goes away. Writing this out, these are likely two different issues with the shared symptom of an ESM package not being able to import either of them.🔎 Search Terms
esm module nodenext
🕗 Version & Regression Information
[email protected]
⏯ Playground Link
Minimal repo: https://github.com/ide/typescript-esm-demo. Dependencies are needed to show the effect.
💻 Code
🙁 Actual behavior
tsc outputs:
🙂 Expected behavior
tsc should compile without errors.
The text was updated successfully, but these errors were encountered: