-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
(v2) Error: Failed to load url when dynamic importing js files generated during tests with relative path #6152
Copy link
Copy link
Closed
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
I was investigating a test failure when upgrading Vitest v2 in vite-plugin-react repo vitejs/vite-plugin-react#347 and this seems to be the cause.
//// src/repro.test.ts
// this works
test("absolute ok", async () => {
await writeFile("src/generated.js", "export default 'hello'");
const mod = await import(path.join(import.meta.dirname, "./generated.js"));
console.log(mod);
});
// this is error
test("relative error", async () => {
await writeFile("src/generated.js", "export default 'hello'");
const mod = await import("./generated.js");
console.log(mod);
});Reproduction
code: https://github.com/hi-ogawa/reproductions/tree/main/vitest-plugin-react-v2
stackblitz: https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vitest-plugin-react-v2?file=src%2Frepro.test.ts
$ rm src/generated.js
$ npx vitest -t relative
FAIL src/repro.test.ts > relative error
Error: Failed to load url ./generated.js (resolved id: ./generated.js) in /home/projects/rlmibvxopx.github/src/repro.test.ts. Does the file exist?
❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:52451:17System Info
(stackblitz)
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
vitest: 2.0.3 => 2.0.3Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Type
Projects
Status
Discussing