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

Node22 under ESM, tsx running error? SyntaxError: The requested module '../a.js' does not provide an export named 'TestService'? #702

Open
4 tasks done
zurmokeeper opened this issue Feb 28, 2025 · 3 comments
Labels
bug Something isn't working pending triage

Comments

@zurmokeeper
Copy link

zurmokeeper commented Feb 28, 2025

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/zurmokeeper/20250228-tsx-node22-bug

Problem & expected behavior (under 200 words)

Node v22.12.0 Executing npm run test in the root directory, reports an error.

SyntaxError: The requested module '../a.js' does not provide an export named 'TestService'

Not so under node 20.18.1, tsx version v4.19.3.

Image

@zurmokeeper zurmokeeper added bug Something isn't working pending triage labels Feb 28, 2025
@mtmacdonald
Copy link

mtmacdonald commented Feb 28, 2025

In a project with .js files that import ESM functions from .ts files (an old codebase) I'm also hitting SyntaxError: The requested module ... does not provide an export named ... errors.

Image

My codebase doesn't use "type": "module" in package.json yet. I am able to build and run the entrypoint with esbuild directly. I can also confirm the above error only happens in Node 22 or Node 23. But for Node 20, tsx handles this fine:

Image

Following.

@mtmacdonald
Copy link

There is an active PR672 for Node 22 support from October - but the tests don't pass (so probably TSX doesn't support Node 22 yet).

@Antelope-IT
Copy link

Looking at that PR 672, Only some of the tests are failing; tests for node v22.14.0 are already included some of which are passing and some of which are failing. Tests with node version 22.6.0 are passing. So there is some support for Node v22 just not the current LTS version.

Through experimentation I think it can be seen that this bug was caused by a change in Node v22.10.0: that is; my code works with Node 22.9.0 but fails with the above error when run with Node 22.10.0

This is when trying to import from *.cjs in to an ESM module (*.ts with type: module)

The code compiles/builds with tsc, its only when it runs under mocha with tsx for unit tests that this bug occurs.

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

3 participants