-
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
Module resolution behaves differently when typeRoots is specified #59329
Comments
Can you specify exactly one config which you think should behave differently? We're also not super keen on running |
Here's a proper repo you can clone. It's not quite flat because This is the {
"files": ["index.ts"],
"compilerOptions": {
"noEmit": true,
// When "typeRoots" is not specified, this project has 8 compiler errors.
// When "typeRoots" is specified, this project has 1 compiler error.
// "typeRoots": ["./node_modules/@types"],
"module": "Node16",
"moduleResolution": "Node16",
// Preserve/Node10, Preserve/Bundler, and ES2015+/Bundler all have
// differences in behavior depending on the presence of "typeRoots".
// "moduleResolution": "Node10",
// "moduleResolution": "Bundler"
// "module": "Preserve",
// "module": "ES2015",
// "module": "ES2020",
// "module": "ES2022",
// "module": "ESNext",
}
} I also noticed that different combinations of
When Perhaps unsurprisingly, I've found that it's the presence of |
I think this is a duplicate of #47444. I tried to fix it at #58638 and the breaks looked untenable. It may be worth experimenting with resolving |
Marking as a duplicate and scheduling another crack at #47444 for 5.8. (Any fix we can possibly do here is going to be a breaking change, so itβs too late for 5.7.) |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
typeRoots, module resolution, moduleResolution, bundler
π Version & Regression Information
Preserve
since 5.4.2)β― Playground Link
No response
π» Code
No response
π Actual behavior
Setting
typeRoots
to./node_modules/@types
changes how modules are resolved when using the following compiler options:moduleResolution: Node16, module: Node16
moduleResolution: Node10, module: Preserve
moduleResolution: Bundler, module: ES2015 | ES2020 | ES2022 | ESNext | Preserve
π Expected behavior
Setting
typeRoots
to./node_modules/@types
should not change how modules are resolved.Additional information about the issue
Clone this gist and execute
setup.sh
to see a minimal reproduction. It sets up a package with various export types, and tries to compile a file with corresponding imports using variousmodule
/moduleResolution
combinations. Not all imports are expected to work for all combinations, but the errors are expected to be the same regardless of whethertypeRoots
is specified. If the errors are different, the script will log the errors along with the compiler options used. (No output from the script means there were no mismatched errors.)Sample output:
The text was updated successfully, but these errors were encountered: