Bug Report
🔎 Search Terms
nodenext createrequire
nodenext import
node12
Discussed here:
#46452 (comment)
🕗 Version & Regression Information
typescript@4.7.0-dev.20220428
This is the behavior in every version I tried, and I reviewed the FAQ for entries about NodeNext
I was unable to test this on prior versions because this feature is new in 4.7
⏯ Playground Link
The playground does not allow specifying package.json "type", so instead, I've published a minimal reproduction here:
https://github.com/cspotcode/repros/tree/ts-nodenext-emit-bug
💻 Code
tsconfig.json
package.json
// This should emit a call to createRequire(import.meta.url)importfoo= require('foo');foo;🙁 Actual behavior
When target is <= es2018, the import is entirely omitted from the emit.
It looks like this: https://github.com/cspotcode/repros/blob/ts-nodenext-emit-bug/dist/example.js
🙂 Expected behavior
The import is emitted, including a call to createRequire()
It should look like this: https://github.com/cspotcode/repros/blob/ts-nodenext-emit-bug/dist-with-bug-workaround/example.js
import{createRequireas_createRequire}from"module";const__require=_createRequire(import.meta.url);// This should emit a call to createRequire(import.meta.url)constfoo=__require("foo");foo;
Bug Report
🔎 Search Terms
nodenext createrequire
nodenext import
node12
Discussed here:
#46452 (comment)
🕗 Version & Regression Information
typescript@4.7.0-dev.20220428
This is the behavior in every version I tried, and I reviewed the FAQ for entries about NodeNext
I was unable to test this on prior versions because this feature is new in 4.7
⏯ Playground Link
The playground does not allow specifying package.json "type", so instead, I've published a minimal reproduction here:
https://github.com/cspotcode/repros/tree/ts-nodenext-emit-bug
💻 Code
tsconfig.json
{ "compilerOptions": { // This bug occurs when using the new Node module type and resolver// And when target is <= es2018"module": "NodeNext", "moduleResolution": "NodeNext", "target": "es2018" } }package.json
{ "type": "module" }🙁 Actual behavior
When target is <= es2018, the import is entirely omitted from the emit.
It looks like this: https://github.com/cspotcode/repros/blob/ts-nodenext-emit-bug/dist/example.js
🙂 Expected behavior
The import is emitted, including a call to
createRequire()It should look like this: https://github.com/cspotcode/repros/blob/ts-nodenext-emit-bug/dist-with-bug-workaround/example.js