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

Fix ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows #344

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

pirxthedev
Copy link
Contributor

@pirxthedev pirxthedev commented Jun 22, 2023

When attempting to build hypothesis/client on a Windows 10 machine, I got the following error:

~\Code\hypothesis-client> yarn run build
yarn run v1.22.19
$ cross-env NODE_ENV=production gulp build
[21:49:17] Using gulpfile ~\Code\hypothesis-client\gulpfile.mjs
[21:49:17] Starting 'build'...
[21:49:17] Starting 'build-js'...
[21:49:17] Starting 'build-css'...
[21:49:17] Starting 'build-fonts'...
[21:49:17] Starting 'build-annotator-tailwind-css'...
[21:49:17] Starting 'build-sidebar-tailwind-css'...
[21:49:17] Starting 'build-standalone-css'...
[21:49:17] 'build-js' errored after 15 ms
[21:49:17] 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 ESMLoader.resolve (node:internal/modules/esm/loader:842:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at readConfig (file:///C:/Users/pirx/Code/hypothesis-client/node_modules/@hypothesis/frontend-build/lib/rollup.js:13:44)
[21:49:17] 'build' errored after 21 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have confirmed that the proposed change fixes the problem in my environment. I have not checked whether this change breaks the build on other platforms.

Copy link
Contributor

@acelaya acelaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm this works on Linux.

@robertknight could you try on Mac?

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix.

For my future reference, nodejs/node#31710 has full background on the issue. The TL;DR is that static and dynamic imports expect relative or absolute URLs. Relative URLs are resolved against the URL of the current module. On Linux/macOS new URL('/absolute/path', 'file:///path/to/current/module.mjs') happens to work and produce a file: URL that can be loaded. On Windows however this expands to new URL('C:\\absolute\\path', 'file:///path/to/current/module.mjs') which produces a URL with a c: scheme that can't be import-ed.

@robertknight robertknight merged commit 17cbedd into hypothesis:main Jun 22, 2023
1 check passed
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.

3 participants