You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__dirname;
^
ReferenceError: __dirname is not defined in ES module scope
at <anonymous> (/Users/abraham/PhpstormProjects/repro/index.ts:1:1)
at ModuleJob.run (node:internal/modules/esm/module_job:272:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:580:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5)
Node.js v23.6.0
demonstrating that tsx is incorrectly executing this script in ESM mode, even though the package.json includes "type": "commonjs".
Making any of the following changes makes the issue go away:
Switching from Node 23.6 to 23.5. (Type stripping was turned on by default in this release, but I'm not sure if that's the problem: 23.6 changelog)
Removing "type": "commonjs" from package.json.
Adding --no-experimental-strip-types.
Adding --no-experimental-require-module.
Executing the TS file directly with node index.ts (using the aforementioned on-by-default type stripping)
Bugs are expected to be fixed by those affected by it
I'm interested in working on this issue
Compensating engineering work will speed up resolution and support the project
I'm willing to offer $10 for financial support
The text was updated successfully, but these errors were encountered:
abrahamguo
changed the title
Regressio: executed in ESM scope with "type": "commonjs" in Node 23.6
Regression: executed in ESM scope with "type": "commonjs" in Node 23.6
Jan 25, 2025
Acknowledgements
Minimal reproduction URL
https://github.com/abrahamguo/repro/tree/tsx
Problem & expected behavior (under 200 words)
Running
npx tsx index.ts
producesdemonstrating that
tsx
is incorrectly executing this script in ESM mode, even though thepackage.json
includes"type": "commonjs"
.Making any of the following changes makes the issue go away:
"type": "commonjs"
frompackage.json
.--no-experimental-strip-types
.--no-experimental-require-module
.node index.ts
(using the aforementioned on-by-default type stripping)Bugs are expected to be fixed by those affected by it
Compensating engineering work will speed up resolution and support the project
The text was updated successfully, but these errors were encountered: