Problems with __esModule marker in JS/TS mixed node16 environemnt #58127
Labels
Bug
A bug in TypeScript
Domain: JS Emit
The issue relates to the emission of JavaScript
Fix Available
A PR has been opened for this issue
Milestone
🔎 Search Terms
__esModule, node16, module resolution
🕗 Version & Regression Information
This caused a crash when I assumed synthetic default import would work on a cjs js file, but the resulting output from the cjs js file got the __esModule marker stopping the synthetic default import mechanism. The bug is that the file is certainly not a transpiled es module.
I could not make a convincing repro in playground, so I made a full repo instead:
https://github.com/meros/tsc-module-bug-repro
⏯ Playground Link
https://github.com/meros/tsc-module-bug-repro
💻 Code
In a node16 project, using a mix of js/ts files. CommonJS JS source files get the __esModule marker causing synthetic default imports to fail:
🙁 Actual behavior
synthetic default import fails due to misleading __esModule marker in output file
🙂 Expected behavior
a JS source that should be treated as, or is detected to be, a commonjs that is transpiled to a commonjs module should NOT get the __esModule marker.
Additional information about the issue
This bug makes the transition to modules in node projects harder and more error prone. I spent at least a day trying to figure out if I misconfigured something or misunderstood the module system but I cannot see how this is not a bug in tsc related to node16 handling.
The text was updated successfully, but these errors were encountered: