-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Failed to import dynamically generated files on SSR when server.fs.cachedChecks #17760
Copy link
Copy link
Closed
Closed
Copy link
Labels
p4-importantViolate documented behavior or significantly improves performance (priority)Violate documented behavior or significantly improves performance (priority)
Description
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
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.4Used Package Manager
pnpm
Logs
No response
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.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- 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
p4-importantViolate documented behavior or significantly improves performance (priority)Violate documented behavior or significantly improves performance (priority)