-
Notifications
You must be signed in to change notification settings - Fork 320
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 URL file://
path handling on Windows
#3584
Conversation
Compatible cross-platform “path to file URL” changes must use `pathToFileURL()` ``` 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 'd:' ```
Compatible cross-platform “file URL to path” changes must use `fileURLToPath()`
Test runs on Windows must be run manually: |
7f46a8c
to
315654e
Compare
When a build is skipped (already in cache) we assume the global “npm get cache” location at `~/.npm` still has all the binaries we need such as eslint, stylelint, tsc etc But Windows can’t find them unless `node_modules/.bin` is restored
315654e
to
2398bd6
Compare
@@ -48,6 +48,9 @@ jobs: | |||
- name: Checkout | |||
uses: actions/checkout@v3 | |||
|
|||
- name: Restore dependencies | |||
uses: ./.github/workflows/actions/install-node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move this line here for Windows to find node_modules/.bin/tsc
Unlike our Linux runners it's not in the global “npm get cache” location at ~/.npm
> build:types
> tsc --build tsconfig.build.json
'tsc' is not recognized as an internal or external command,
operable program or batch file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers for catching that! Looks good to me ⛵
This PR fixes two Windows regressions added in #3527 and #3372
URL file paths with drive letters
D:/
confusepath.relative()
and throw errors inawait import()
: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 'd:'
File URLs with absolute paths
On Windows, Node.js
file://
URL paths look like:Converting URLs to paths incorrectly
But the property
new URL(file).pathname
includes a leading forward slash:We hadn't realised this breaks
path.relative()
on Windows with paths joined and not resolved:'..\\..\\..\\..\\D:\\path\\to\\project\\packages\\govuk-frontend\\src\\govuk\\components\\character-count\\_index.scss'
Converting URLs to paths correctly
After investigating this issue (also "Converting between URLs and file paths") we see that:
pathToFileURL()
fileURLToPath()