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
The newly released version v4.9.1 doesn't handle absolute paths (4.9.0 doesn't have this issue).
What I expected
I expected to be able to run the following with tsx index.mts:
// index.mtsimportpathfrom"node:path";import{fileURLToPath}from"node:url";importfsfrom"node:fs";const__dirname=path.dirname(fileURLToPath(newURL(import.meta.url)));constmoduleRelativePath="./hello.mts";constmoduleAbsolutePath=path.resolve(__dirname,moduleRelativePath);fs.writeFileSync(moduleAbsolutePath,`export const message = "Hello, world!";`);awaitimport(moduleAbsolutePath);// Doesn't work
Error stack trace
node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".mts" for <redacted>/hello.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:866:22)
at async x (file:///<redacted>/.npm/_npx/dcefadc2074ecd1f/node_modules/tsx/dist/esm/index.mjs?1714902597374:2:1744)
at async nextLoad (node:internal/modules/esm/hooks:866:22)
at async Hooks.load (node:internal/modules/esm/hooks:449:20)
at async handleMessage (node:internal/modules/esm/worker:196:18) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Documentation links
It happens because an absolute path is not considered a path in the custom resolver and then the early return at the end of the if block skips the resolution:
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/tsx-4-9-1-import-from-absolute-path-issue
Version
4.9.1
Node.js version
v20.12.2
Package manager
npm
Operating system
macOS
Problem & expected behavior (under 200 words)
The newly released version v4.9.1 doesn't handle absolute paths (4.9.0 doesn't have this issue).
I expected to be able to run the following with
tsx index.mts
:It happens because an absolute path is not considered a path in the custom resolver and then the early return at the end of the if block skips the resolution:
tsx/src/esm/hook/resolve.ts
Lines 130 to 150 in 96bc596
Contributions
The text was updated successfully, but these errors were encountered: