Skip to content
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

Importing ES6 modules does not work on Windows #35

Open
mmomtchev opened this issue Mar 20, 2023 · 3 comments · May be fixed by #38
Open

Importing ES6 modules does not work on Windows #35

mmomtchev opened this issue Mar 20, 2023 · 3 comments · May be fixed by #38

Comments

@mmomtchev
Copy link

Importing a worker in ES6 mode fails on Windows:

worker = new Worker(new URL('./worker.js', import.meta.url), {type: 'module'});

ends with:

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at new NodeError (node:internal/errors:400:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1055:11)
    at defaultResolve (node:internal/modules/esm/resolve:1135:3)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at defer (C:\Users\mmom\src\sqlite-wasm-http\node_modules\ts-node\src\esm.ts:159:23)
    at entrypointFallback (C:\Users\mmom\src\sqlite-wasm-http\node_modules\ts-node\src\esm.ts:168:34)
    at C:\Users\mmom\src\sqlite-wasm-http\node_modules\ts-node\src\esm.ts:202:16
    at addShortCircuitFlag (C:\Users\mmom\src\sqlite-wasm-http\node_modules\ts-node\src\esm.ts:409:21)
    at resolve (C:\Users\mmom\src\sqlite-wasm-http\node_modules\ts-node\src\esm.ts:197:12)
    at nextResolve (node:internal/modules/esm/loader:163:28) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

The problem is nodejs/node#31710
(yes, initially, mostly everyone is as surprised as I was - but it seems that everyone agrees that this is how it should be)

It comes from this import:

import(mod)

Which happens after removing the file:/// part here:

mod = URL.fileURLToPath(new URL.URL(url, baseUrl));

@mmomtchev mmomtchev linked a pull request Mar 20, 2023 that will close this issue
@Firegarden
Copy link

I have been stuck on this error for half a day and I am glad to see it here. I tried replacing line 178 of my local node.js file but it's still throwing the same error.

Is there a known work around for this until its fixed in the release version?

@Firegarden
Copy link

mention the fix in the pull request does not address the commonjs node file

Question why is my esm project even calling into the cjs file? I have my type set to module

@mmomtchev
Copy link
Author

mmomtchev commented Mar 24, 2023

In the meantime, I have @mmomtchev/web-worker

I will add your fix for the CJS version

However, it would be also great to hear from the module maintainers? Is this module still maintained? It seems to be somewhat popular.

I am surprised that something as fundamental as this has been left out to gather dust. Now that we have fetch in Node.js, this is the last significant blocker for low-level browser projects that do not manipulate the DOM.

Isn't it time to have a grand unified API? I would even dare to suggest that the ES specification should probably include multithreading with a standard import mechanism. What do the high priests of the TSC think about this?

Especially, since there is already a de-facto standard:

const worker = new Worker( new URL( './worker.js', import.meta.url ) )

Everything needed is to write it down as such and implement WebWorker in Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants