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

[Win] ERR_UNSUPPORTED_ESM_URL_SCHEME #39

Open
rtritto opened this issue Aug 3, 2023 · 6 comments
Open

[Win] ERR_UNSUPPORTED_ESM_URL_SCHEME #39

rtritto opened this issue Aug 3, 2023 · 6 comments

Comments

@rtritto
Copy link

rtritto commented Aug 3, 2023

Related to v5.0.0-beta.0 (it correctly works with v4.0.0-beta.10)

import { load } from 'ts-import'
await load('./a.mts', { compiledJsExtension: '.cjs' })

Result

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and 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:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:964:11)
    at defaultResolve (node:internal/modules/esm/resolve:1040:3)
    at nextResolve (node:internal/modules/esm/hooks:654:28)
    at resolve$1 (file:///C:/<PROJECT_PATH>/.pnp.loader.mjs:1960:14)
    at nextResolve (node:internal/modules/esm/hooks:654:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:309:30)
    at ESMLoader.resolve (node:internal/modules/esm/loader:312:26)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:172:38)
    at ESMLoader.import (node:internal/modules/esm/loader:276:22) {
  type: 'Error',
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
@pedromcunha
Copy link

Also running into this issue, any workarounds for windows in the meantime?

@rtritto
Copy link
Author

rtritto commented Aug 4, 2023

With yarn berry can be created a patch.
Maybe url.pathToFileURL is needed as parameter of the dynamic async import.

@xavierlaffargue
Copy link

Same issue on my side, any workarround?

@Fasteroid
Copy link

Help!

@luixo
Copy link

luixo commented Mar 22, 2024

@rtritto

Maybe url.pathToFileURL is needed as parameter of the dynamic async import.

Unfortunately, combining with cwd makes passed file url change from /Users/<user>/my-project/file.ts to /Users/<user>/my-project/file:/Users/<user>/my-project/file.ts.

@luixo
Copy link

luixo commented Mar 23, 2024

Simple solution is to change both cases of

const loaded = await import(jsPath);

to

import * as path from 'node:path';
const loaded = await import(url.pathToFileURL(jsPath));

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

No branches or pull requests

5 participants