-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
ERR_UNSUPPORTED_ESM_URL_SCHEME
when dyanmic import in windows
#345
Comments
Apparently this is by design: nodejs/node#34765 (comment) Does this work in any other Windows environments? eg. different versions of Node.js or TypeScript |
It works after temp fix in win10 with typescript v4.5 ~ v4.8, node v12.20.0, node v14.20.0, node 16.14.2. here is test actions: |
Feel free to open a PR |
I ran into the same issue, but I got it working when using not an absolute path, but a relative path as configured in the
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
} dynamic import const name = "mydynamicimport";
await import(`@/${name}`); Actual problem: absolute path on WindowsSo the "issue" here is the usage of an absolute path, which is not working on Windows. You would have to use a proper URL: import path from "node:path";
import { pathToFileURL } from "node:url";
export async function dynamicImport(fullPath: string) {
const fileURL = pathToFileURL(fullPath).href;
return import(fileURL);
}
// Usage example, assuming your mydynamicimport.ts is inside of "src"
await dynamicImport(path.join(process.cwd(), "src", "mydynamicimport")); This will produce an URL like this: |
It works when dynamic importing a literal:
|
Is esbuild-kit/esm-loader#39 a proper fix? I'd like to back-port it to tsx if it works. |
I'm currently wondering if this is even a tsx issue, or if this is a Node.js issue ya'll are trying to patch with tsx? Specifically, does this work in Node (no tsx) on Windows? import path from "path"
const abs_path = path.resolve('./b.ts', ); // absolute path
import(abs_path) To determine this, I'd throw the above snippet in a GitHub repo with CI on ubuntu and windows running it. |
@privatenumber very much appears to be a Node issue itself |
Thanks for verifying @geisterfurz007 Closing as it's expected behavior. |
Description
In windows, Using dynamic import with absolute path cause
ERR_UNSUPPORTED_ESM_URL_SCHEME
errorReproduction
node --loader @esbuild-kit/esm-loader a.ts
extra
tsx
has same error.The text was updated successfully, but these errors were encountered: