Skip to content
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

Regression: executed in ESM scope with "type": "commonjs" in Node 23.6 #694

Open
5 of 6 tasks
abrahamguo opened this issue Jan 25, 2025 · 0 comments
Open
5 of 6 tasks
Labels
bug Something isn't working pending triage

Comments

@abrahamguo
Copy link

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I understand this is a bug tracker and anything other than a proven bug will be closed
  • I understand this is a free project and relies on community contributions
  • I read and understood the Contribution guide

Minimal reproduction URL

https://github.com/abrahamguo/repro/tree/tsx

Problem & expected behavior (under 200 words)

Running npx tsx index.ts produces

__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
@abrahamguo abrahamguo added bug Something isn't working pending triage labels Jan 25, 2025
@abrahamguo 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

1 participant