-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: "node"
condition does not work when using moduleResolution=bundler
#61357
Comments
How else would you be able to disable this condition? What if you bundle exclusively for the browser target? |
The
But what if you don't bundle exclusively for the browser? For instance, Next.js uses the bundler mode even for its Node.js backend. I would expect the TypeScript compiler to transpile code without altering its runtime behavior. Therefore, I think, the ideal solution would be to derive the node condition from the runtime environment as originally intended. For scenarios where optimization is needed, such as creating a bundle solely for the browser and removing Node.js-specific functionality, that responsibility should lie with a dedicated bundler, not with the primary role of the TypeScript compiler. If, for any reason, the node condition must be hard-coded upfront when using the |
I wouldn't say it disabled it. It just didn't enable it. I think it's a somewhat important difference here.
Runtimes can do whatever they want. That's why this mode is flexible. You are in control over all of the conditions that should be used.
How would TypeScript infer what your runtime is doing and what conditions it should enable? |
This correctly pinpoints the core issue: TypeScript cannot infer the runtime environment. In other words, at compile time, you can only determine that the Therefore, when converting ECMAScript Modules to a bundle, the bundler must account for both scenarios to ensure correct runtime behavior. |
Demo Repo
https://github.com/Borewit/typescript-bundler-with-node-node-condition
Which of the following problems are you reporting?
The module specifier resolves at runtime, but not at build time
Demonstrate the defect described above with a code sample.
Run
tsc --showConfig
and paste its output hereRun
tsc --traceResolution
and paste its output herePaste the
package.json
of the importing module, if it existsPaste the
package.json
of the target module, if it existsAny other comments can go here
When the
"moduleResolution"
resolution is set to"bundler"
,"node"
specific export (depending on that export condition) cannot be imported.Caused by:
TypeScript/src/compiler/moduleNameResolver.ts
Lines 774 to 776 in c85e626
Related issues:
parseFile
if the TypeScript compilermoduleResolution
is set tobundler
Borewit/music-metadata#2370Workaround:
The text was updated successfully, but these errors were encountered: