🔎 Search Terms
nodenext, module, __dirname
🕗 Version & Regression Information
Version 5.4.5
⏯ Playground Link
No response
💻 Code
package.json
tsconfig.json
{
"compilerOptions": {
"module": "NodeNext"
},
"include": ["src"]
}file.ts
🙁 Actual behavior
No compiler error, but this causes a runtime error in Node:
ReferenceError: __dirname is not defined in ES module scope
🙂 Expected behavior
That the compiler issues an error similar to the inverse situation.
For example, when targeting CommonJS:
package.json
file.ts
console.log(import.meta.dirname)
The compiler issues the following error:
error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.
Additional information about the issue
Perhaps there is a good reason for this that I'm not understanding, but I would think tsc should issue an error or warning for any syntax that would produce a runtime error.
Here is a more complete example: https://github.com/knightedcodemonkey/tsc-module-globals
npm installnpm run esm (note no compile error but the output causes a runtime error)npm run cjs (note there is a compile error)
🔎 Search Terms
nodenext, module, __dirname
🕗 Version & Regression Information
Version 5.4.5
⏯ Playground Link
No response
💻 Code
package.json
tsconfig.json
{ "compilerOptions": { "module": "NodeNext" }, "include": ["src"] }file.ts
🙁 Actual behavior
No compiler error, but this causes a runtime error in Node:
🙂 Expected behavior
That the compiler issues an error similar to the inverse situation.
For example, when targeting CommonJS:
package.json
file.ts
The compiler issues the following error:
Additional information about the issue
Perhaps there is a good reason for this that I'm not understanding, but I would think
tscshould issue an error or warning for any syntax that would produce a runtime error.Here is a more complete example: https://github.com/knightedcodemonkey/tsc-module-globals
npm installnpm run esm(note no compile error but the output causes a runtime error)npm run cjs(note there is a compile error)