Skip to content

Importing ES6 modules does not work on Windows #35

Description

@mmomtchev

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));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions