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

[Windows] Failed to run ESM, throwing ERR_UNSUPPORTED_ESM_URL_SCHEME #266

Closed
compulim opened this issue Oct 6, 2021 · 4 comments
Closed

Comments

@compulim
Copy link

compulim commented Oct 6, 2021

Description

When running node-dev ./index.mjs on Windows, Node.js (14.* and 16.*) will throw ERR_UNSUPPORTED_ESM_URL_SCHEME. It works on Ubuntu.

According to doc, I renamed to .mjs and I believe this is the only change needed for ESM.

When using ESModule syntax and .mjs files, node-dev will automatically use a loader to know which files to watch.

Repro steps

I created a repo for bug repro, with GitHub Actions configured to run on both Ubuntu and Windows.

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:791:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at Loader.import (internal/modules/esm/loader.js:177:28)
    at internal/process/esm_loader.js:57:31
    at initializeLoader (internal/process/esm_loader.js:62:5)
    at Object.loadESM (internal/process/esm_loader.js:67:11)
    at runMainESM (internal/modules/run_main.js:47:31)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:73:5)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

The workflow runs the following steps:

  1. Install Node.js (12.x, 14.x, 16.x)
  2. npm install (with node-dev@^7.0.0)
  3. npm start
    • It runs node-dev ./index.mjs
  4. When index.mjs is loaded, it import hello from './hello.mjs'

To repro without a Windows box, please fork the repo and see the result of GitHub Actions. 😉

Instead of npm start, I also tried the followings and got same error:

  • node_modules\.bin\node-dev .
  • node_modules\.bin\node-dev ./index.mjs
@bjornstar
Copy link
Collaborator

According to nodejs/node#31710, we should use pathToFileUrl.

It's probably a good idea to add a windows build in our github actions.

@bjornstar
Copy link
Collaborator

I've added windows to the tests and can see the ESM tests are failing. I'll take a look at it when I get some more time.

@kherock
Copy link
Contributor

kherock commented Mar 26, 2022

I believe this is resolved by #279. Using fileURLToPath in the ESM loader seems to have fixed those tests on Windows

@bjornstar
Copy link
Collaborator

Tests are looking great, thanks @kherock. I'll go ahead and cut a release. Let's call this fixed in v7.4.0

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

3 participants