fix(bin): support Node.js 22 on Windows by importing CLI via file:// URL #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Windows with Node.js 22.x, invoking the @ngx-playwright/test binary fails with:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]:
Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
Root cause
packages/test/bin.cjs resolves the Playwright CLI to an absolute Windows path and passes it directly to import(). Since Node 22 treats ESM specifiers as URLs, C:... is interpreted as the unsupported scheme c: and is rejected.
Fix
Convert the absolute path to a file:// URL using pathToFileURL(...) before calling import().
Compatibility:
-Works on Node 18/20/22
-Cross-platform (Windows/macOS/Linux)
-No breaking changes
How I tested:
Windows 11
Node.js 22.13.1 (repro), Node.js 20.17.0 (sanity)
npx playwright --version and running tests via the package binary
Notes:
An alternative would be using createRequire(import.meta.url) to require() the CLI, but the file:// approach keeps the current dynamic import() and fixes the ESM URL issue cleanly.
Thanks!