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

Use pathToFileURL (Windows fix) #7

Closed
wants to merge 1 commit into from

Conversation

Maxim-Mazurok
Copy link

I was doing this:

import { dynamicImport } from "tsimportlib";
//...
const { default: filterAsync } = (await dynamicImport(
    "node-filter-async",
    module,
  )) as typeof import("node-filter-async");

And was getting this:

Error: 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:972:11)
    at defaultResolve (node:internal/modules/esm/resolve:1051:3)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:307:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:156:32)
    at DefaultModuleLoader.import (node:internal/modules/esm/loader:266:12)
    at importModuleDynamically (node:internal/modules/cjs/loader:1197:37)
    at importModuleDynamicallyWrapper (node:internal/vm/module:428:21)
    at importModuleDynamically (node:internal/vm:105:46)
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:87:14) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Fix inspired by nuxt/nuxt#19676

@kbzowski kbzowski mentioned this pull request May 7, 2023
@SnowMarble
Copy link
Contributor

SnowMarble commented May 19, 2023

since the issue was fixed in #6, this pr needs to be closed

@Maxim-Mazurok
Copy link
Author

Maxim-Mazurok commented May 19, 2023

Yeah, your fix seems to work for me, likely even better than this one because looks like I put pathToFileURL to the wrong import.

I'm still having an issue #8 with this lib tho, will patch it up.

@Maxim-Mazurok Maxim-Mazurok deleted the patch-1 branch May 19, 2023 22:39
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 this pull request may close these issues.

2 participants