-
-
Couldn't load subscription status.
- Fork 84
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
@swc-node/register fails to import module with file URL since v1.10.0.
Reproduction
Minimal reproduction example with the following files:
├── ... ├── test.ts ├── module.mjs └── ... Content of test.ts:
import { join } from 'node:path'; import { cwd } from 'node:process'; async function importModule() { const file = './module.mjs'; const filePath = `file:///${join(cwd(), file)}`; console.log('Importing module:', filePath); const module = await import(filePath); console.log('Imported module:', module); } importModule();Content of module.mjs:
export function hello() { return 'Hello, world!'; }Run the test.ts file, using this command:
node --import @swc-node/register/esm-register test.tsResult
Importing module: file:///E:\My\Path\module.mjs node:internal/process/promises:394 triggerUncaughtException(err, true /* fromPromise */); ^ TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected undefined or a fully resolved URL string to be returned for the "responseURL" from the "node:internal/modules/esm/load 'load'" hook but got type string ('file:///...'). at Hooks.load (node:internal/modules/esm/hooks:412:13) at async MessagePort.handleMessage (node:internal/modules/esm/worker:199:18) { code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' } Node.js v22.11.0With versions older than v1.10.0, the result is expected:
Importing module: file:///E:\My\Path\module.mjs Imported module: [Module: null prototype] { hello: [Function: hello] } Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working