We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In Node.js, we can import ~.mjs with a path like import('file:///path/to/%7E.mjs'). In Vitest, on the other hand, it causes an error.
~.mjs
import('file:///path/to/%7E.mjs')
Also, Errors are caused by any URL-encoded filename other than ~.mjs, such as |.mjs.
|.mjs
⚠️ WARNING: This reproduction depends on the behavior of nodejs/node#54545. You need Node.js v22.12.0+ or v23.1.0+ to reproduce the problem.
https://github.com/mizdra/repro-vitest-import-with-tilde
$ npm i $ npm run test:node-test > [email protected] test:node-test > node --test node-test.test.mjs ✔ import test 1 (2.104084ms) ✔ import test 2 (0.176542ms) ℹ tests 2 ℹ suites 0 ℹ pass 2 ℹ fail 0 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 61.934917 $ npm run test:vitest -- --run > [email protected] test:vitest > vitest vitest.test.mjs --run RUN v2.1.8 /Users/mizdra/src/localhost/gomi/repro-node-path-to-file-url-with-tilda ❯ vitest.test.mjs (2) ✓ import test 1 × import test 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ FAIL vitest.test.mjs > import test 2 Error: Failed to load url /Users/mizdra/src/localhost/gomi/repro-node-path-to-file-url-with-tilda/%7E.mjs (resolved id: /Users/mizdra/src/localhost/gomi/repro-node-path-to-file-url-with-tilda/%7E.mjs). Does the file exist? ❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:51920:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ Test Files 1 failed (1) Tests 1 failed | 1 passed (2) Start at 00:36:25 Duration 230ms (transform 20ms, setup 0ms, collect 9ms, tests 7ms, environment 0ms, prepare 48ms)
System: OS: macOS 15.1.1 CPU: (10) arm64 Apple M1 Pro Memory: 2.75 GB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.12.0 - ~/.local/share/mise/installs/node/22.12.0/bin/node npm: 10.9.0 - ~/.local/share/mise/installs/node/22.12.0/bin/npm pnpm: 8.15.1 - ~/.local/share/mise/installs/node/22.12.0/bin/pnpm bun: 1.1.33 - /opt/homebrew/bin/bun Watchman: 2024.10.21.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 131.0.6778.140 Chrome Canary: 133.0.6856.0 Safari: 18.1.1 Safari Technology Preview: 18.2 npmPackages: vitest: ^2.1.8 => 2.1.8
npm
The text was updated successfully, but these errors were encountered:
The source of the error is the Vite code.
https://github.com/vitejs/vite/blob/63b82f1e29a00d06a82144fd03ea8d6eff114290/packages/vite/src/node/server/transformRequest.ts#L329-L333
It may be a bug in Vite. However, I have not yet checked if this is true.
Sorry, something went wrong.
Vite itself should support this since Vite 6 vitejs/vite#18422 https://stackblitz.com/edit/github-rgyum6yj?file=repro-vite.mjs I thought Vitest (vite-node) already did, but apparently not. Probably vite-node does wrong normalization of path.
Thanks for addressing this issue.
FYI: TypeScript has the same problem with the resolution algorithm, so I created an issue. microsoft/TypeScript#60771
Successfully merging a pull request may close this issue.
Describe the bug
In Node.js, we can import
~.mjs
with a path likeimport('file:///path/to/%7E.mjs')
. In Vitest, on the other hand, it causes an error.Also, Errors are caused by any URL-encoded filename other than
~.mjs
, such as|.mjs
.Reproduction
https://github.com/mizdra/repro-vitest-import-with-tilde
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: