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 import dynamically generated files on SSR when server.fs.cachedChecks #17760

Closed
7 tasks done
hi-ogawa opened this issue Jul 25, 2024 · 1 comment
Closed
7 tasks done
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jul 25, 2024

Describe the bug

Related issue on Vitest vitest-dev/vitest#6152

Importing dynamically generated js files during runtime seems to cause Error: Failed to load url ....
It works when setting server.fs.cachedChecks: true.

  • src/repro.js
import { writeFile } from "node:fs/promises";

async function main() {
	await writeFile("src/generated.js", "export default 'hello'");
	const mod = await import("./generated.js");
	console.log(mod);
}

await main();
  • repro-vite.js
import { createServer } from "vite";

async function main() {
	const server = await createServer({
		configFile: false,
		server: {
			fs: {
				// works when disabling `cachedChecks`
				// cachedChecks: false,
			},
		},
	});
	await server.ssrLoadModule("/src/repro.js");
        // oddly it works if load full path
        // await server.ssrLoadModule(path.resolve("src/repro.js")))
}

main();
  • Command
$ rm -f src/generated.js && node repro-vite.js
Error: Failed to load url /src/generated.js (resolved id: /src/generated.js). Does the file exist?
    at loadAndTransform (file:///home/projects/gqairrmzbn.github/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:52451:17)
    at async instantiateModule (file:///home/projects/gqairrmzbn.github/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:53403:44) {
  code: 'ERR_LOAD_URL'
}

Node.js 18.20.3

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/vitest-plugin-react-v2

Steps to reproduce

Open https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vitest-plugin-react-v2?file=README.md and run node repro-vite.js.

System 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:
    vite: 5.3.4 => 5.3.4

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Closing as server.fs.cachedChecks is removed and works as false since Vite 6.0.0.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 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)
Projects
None yet
Development

No branches or pull requests

3 participants