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
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
$ npx ts-node --esm src/test.mts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".mts"for /***/ts-node-bug/src/test.mts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
at defaultLoad (node:internal/modules/esm/load:143:22)
at async nextLoad (node:internal/modules/esm/hooks:865:22)
at async nextLoad (node:internal/modules/esm/hooks:865:22)
at async Hooks.load (node:internal/modules/esm/hooks:448:20)
at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
$ node --loader ts-node/esm src/test.mjs
(node:65265) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'(Use `node --trace-warnings ...` to show where the warning was created)file:///****/ts-node-bug/src/test.mts:1import { foo } from "./lib.js"; ^^^SyntaxError: Named export'foo' not found. The requested module './lib.js' is a CommonJS module, which may not support all module.exports as named exports.CommonJS modules can always be imported via the default export, for example using:import pkg from './lib.js';const { foo } = pkg; at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21) at async ModuleJob.run (node:internal/modules/esm/module_job:214:5) at async ModuleLoader.import (node:internal/modules/esm/loader:329:24) at async loadESM (node:internal/process/esm_loader:28:7) at async handleMainPromise (node:internal/modules/run_main:113:12)Node.js v20.11.1
$ node --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));' src/test.mts cluster: prod
file:///***/ts-node-bug/src/test.mts:1
import { foo } from "./lib.js";
^^^
SyntaxError: Named export'foo' not found. The requested module './lib.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from './lib.js';
const { foo } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.1
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: