-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
ts-node cannot run mixed ESM/CJS project #2110
Comments
I wanted to create a new issue targeting the same problem but then I found this one so I am commenting here. See this stackblitz. // main.cts
(async () => {
const dep = await import('./dep.mjs');
console.log(dep);
})() // dep.mts
export const dep = 'dependency'; I expected
|
It appears this broke in Node 18.19 and versions released since have the issue. There have been multiple issues tracking facets of it, in multiple repositories (node, typescript, ts-node, esbuild, tsx among others), over the last few months, but no resolution. In #2094 the common strategy is to work around the issue - either downgrade Node to 18.18, or use whatever alternative works in your scenario, for example The scenario is very simple: it happens in mixed CJS/ESM repositories, using TS in development with tooling that isn't always new, and inevitably some dependencies that don't support a global switch to modules in package.json. Node and some tooling (tsx) defaults to CJS in the absence of I'd love if |
Search Terms
ESM CJS mixed project
SyntaxError: Named export not found. The requested module is a CommonJS module, which may not support all module.exports as named exports.
Expected Behavior
ts-node works and prints
BAR
Actual Behavior
$ npx tsc && node dist/test.mjs BAR
Steps to reproduce the problem
run this:
ts-node-bug.zip
Minimal reproduction
lib.ts (inferred as CommonJS module)
test.mts (ESM)
Specifications
ts-node v10.9.2
node v20.11.1
compiler v5.4.2
The text was updated successfully, but these errors were encountered: