vite
vite copied to clipboard
Fails on running in a symbolic linked directory
Describe the bug
Vite fails when I try to use it in a sym-linked directory.
Run in CMD:
npm create vite@latest my-vue-app -- --template vue
cd my-vue-app
npm install
cd ..
mklink /d linked-dir my-vue-app
cd linked-dir
npm run dev
Error:
VITE v3.0.2 ready in 322 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
file:///C:/projects/my-vue-app/node_modules/vite/dist/node/chunks/dep-1513d487.js:36967
fileHash: getHash(metadata.hash + depsInfo[id].file + JSON.stringify(output.imports)),
^
TypeError: Cannot read properties of undefined (reading 'imports')
at runOptimizeDeps (file:///C:/projects/my-vue-app/node_modules/vite/dist/node/chunks/dep-1513d487.js:36967:89)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Reproduction
Auto-generated
System Info
System:
OS: Windows 10 10.0.19043
Binaries:
Node: 18.2.0 - C:\Program Files\nodejs\node.EXE
npm: 8.9.0 - C:\Program Files\nodejs\npm.CMD
Vite: 3.0.2
Used Package Manager
npm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] 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.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Real life use case: moving C:/projects
(a folder with your projects) to another place, for example, to D:/projects
and creating a symbolic link in the old location that leads to the new location in order to keep all software (that relies on this path (like IDE)) working as earlier.
I expect that it will work totally transparently.
It's likely on this line that we didn't take into account of this specific case.
https://github.com/vitejs/vite/blob/1c1cf43c146b4f48cb730a33b9bfd13946263132/packages/vite/src/node/optimizer/index.ts#L914-L918
Or the other possibility is that esbuild doesn't correctly return the output
after bundling. Would you help check how this path look like on your machine? If it's incorrectly indexing the output
, would also appreciate if you can submit a PR for it.
function esbuildOutputFromId(outputs, id, cacheDirOutputPath) {
const flatId = flattenId(id) + '.js';
// ---
const wd = process.cwd();
const rel = path$n.relative(process.cwd(), path$n.join(cacheDirOutputPath, flatId));
const norm = normalizePath$3(rel);
console.log(wd); // C:\projects\linked-dir
console.log(rel); // node_modules\.vite\deps_temp\vue.js
console.log(norm); // node_modules/.vite/deps_temp/vue.js
console.log(Object.keys(outputs));
// [
// '../linked-dir/node_modules/.vite/deps_temp/vue.js.map',
// '../linked-dir/node_modules/.vite/deps_temp/vue.js'
// ]
// ---
return outputs[normalizePath$3(path$n.relative(process.cwd(), path$n.join(cacheDirOutputPath, flatId)))];
}
I had the same issue and I searched for 30 min ton understand what was going on...
@patak-dev You reopened this Issue? I am currently still experiencing this with v3.2.5 which I would assume would contain the fix since it was released 2 weeks ago. What's the status on this?
I guess this is related with https://github.com/nodejs/node/issues/34866, similar to #10802.
Have the same issue
on node v16.14.0 it shows
VITE v4.0.4 ready in 308 ms
➜ Local: http://127.0.0.1:5173/
➜ Network: use --host to expose
➜ press h to show help
file:///C:/Users/beck/Dropbox/PC/Documents/Projects/Training/my-vite-app/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42832
fileHash: getHash(metadata.hash + depsInfo[id].file + JSON.stringify(output.imports)),
^
TypeError: Cannot read properties of undefined (reading 'imports')
at runOptimizeDeps (file:///C:/Users/beck/Dropbox/PC/Documents/Projects/Training/my-vite-app/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42832:89)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
on node v14.20.0
(node:17836) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'imports' of undefined
at runOptimizeDeps (file:///C:/Users/beck/Dropbox/PC/Documents/Projects/Training/my-vite-app/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42832:89)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17836) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:17836) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
System info
Operating System Windows_NT(10.0.22000) - win32/x64
VITE v4.0.4
Same issue trying to create a template Svelte app.
VITE v4.0.4 ready in 343 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
file:///C:/Users/KARL/Dev/test.LAB/learn.webdev/learning/client/my-svelte-project/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42832
fileHash: getHash(metadata.hash + depsInfo[id].file + JSON.stringify(output.imports)),
^
TypeError: Cannot read properties of undefined (reading 'imports')
at runOptimizeDeps (file:///C:/Users/KARL/Dev/test.LAB/learn.webdev/learning/client/my-svelte-project/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42832:89)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.13.0
I search many sites, finally I know why my program failed to work! Thank you!