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

Failed to load module created in test #6087

Closed
6 tasks done
Kaciras opened this issue Jul 11, 2024 · 5 comments · Fixed by #6109
Closed
6 tasks done

Failed to load module created in test #6087

Kaciras opened this issue Jul 11, 2024 · 5 comments · Fixed by #6109
Labels
p4-important Violate documented behavior or significantly improves performance (priority) windows

Comments

@Kaciras
Copy link

Kaciras commented Jul 11, 2024

Describe the bug

After upgrading Vitest to 2.0.2, I get the error when import a file created in test:

import { afterEach, expect, it } from "vitest";
import { pathToFileURL } from "url";
import { unlinkSync, writeFileSync } from "fs";

const filename = "bar.js";

afterEach(() => unlinkSync(filename));

it("should works", async () => {
	writeFileSync(filename, "export default 123");
	const mod = await import(pathToFileURL(filename).href);
	expect(mod.default).toBe(123);
});
Error: Failed to load url /D:/Coding/JavaScript/vite-svg-sfc/bar.js (resolved id: /D:/Coding/JavaScript/vite-svg-sfc/bar.js). Does the file exist?
    at loadAndTransform (file:///D:/Coding/JavaScript/vite-svg-sfc/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-CzJTQ5q7.js:52400:17)
    at async ViteNodeServer._transformRequest (file:///D:/Coding/JavaScript/vite-svg-sfc/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite-node/dist/server.mjs:524:16)
    at async ViteNodeServer._fetchModule (file:///D:/Coding/JavaScript/vite-svg-sfc/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite-node/dist/server.mjs:486:17)
    at async Proxy.fetch (file:///D:/Coding/JavaScript/vite-svg-sfc/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vitest/dist/vendor/cli-api.FtQZKvQk.js:8093:22)
    at async EventEmitter.<anonymous> (file:///D:/Coding/JavaScript/vite-svg-sfc/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vitest/dist/vendor/index.BpSiYbpB.js:69:20)

It works in Vitest 1.6.0

Reproduction

See above

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 5625U with Radeon Graphics
    Memory: 6.20 GB / 15.31 GB
  Binaries:
    Node: 22.4.1 - D:\Program Files\NodeJS\node.EXE
    npm: 10.8.1 - D:\Program Files\NodeJS\npm.CMD
    pnpm: 9.5.0 - ~\AppData\Roaming\npm\pnpm.CMD
    bun: 1.1.18 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (124.0.2478.67)
    Internet Explorer: 11.0.22621.3527

Used Package Manager

pnpm

Validations

@AriPerkkio
Copy link
Member

Works fine for me:

Copy link

Hello @Kaciras. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@Kaciras
Copy link
Author

Kaciras commented Jul 11, 2024

Seems to be an error only on Windows.

https:/Kaciras/vitest-issue-1/actions/runs/9886516528/job/27306432893

@sheremet-va sheremet-va added windows p4-important Violate documented behavior or significantly improves performance (priority) and removed needs reproduction pending triage labels Jul 11, 2024
@meteorlxy
Copy link

Same error in vuepress. Only failed on windows.

https:/vuepress/core/actions/runs/9934091779/job/27437900959

@syi0808
Copy link
Contributor

syi0808 commented Jul 15, 2024

Same error in vuepress. Only failed on windows.

https:/vuepress/core/actions/runs/9934091779/job/27437900959

I think this is fixed by #6109. Can you wait for the release?

@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority) windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants