vite
vite copied to clipboard
Dependency pre-bundling cache created with outdated files after branch change
Describe the bug
After switching to a branch with different dependencies than the current branch, if vite
is triggered without running npm install
first, the cache will be created with outdated dependency files.
Even after running npm install
, the cache remains outdated since the lockfileHash
is unchanged. This can result in runtime errors that prevent the app from running, requiring a forced re-bundling to fix.
I'm not sure if this bug falls under vite's scope, as the root issue is the mismatch between the lockfile and the dependency files. Running npm install
upon checking out branches or before starting the dev server would fix it, but it requires extra configuration efforts.
On vite's side, this could be solved by hashing all the dependency files under node_modules
(maybe just the package.json
of each dependency), but this might be an overkill.
Maybe we could add some docs under Optimized Dependencies, as this issue can be confusing without understanding what's happening. I'm happy to work on this if an agreement is made.
Reproduction
https://stackblitz.com/~/github.com/govizlora/vite-dep-example
Steps to reproduce
- Go to https://stackblitz.com/~/github.com/govizlora/vite-dep-example or checkout https://github.com/govizlora/vite-dep-example locally. Make sure you are at the default branch
v8
. - (skip if using stackblitz) Run
npm run dev
. The app will render a UUID with no issue. - Stop the dev server and checkout to branch
v3
. - Run
npm run dev
(don't runnpm install
). Notice that the app fails to run, with error likeSyntaxError: The requested module 'http://localhost:5173/node_modules/.vite/deps/uuid.js?v=628fb369' doesn't provide an export named: 'default'
- Even after running
npm install
, the app still fails with the same error.
System Info
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.2.0 => 5.2.12
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.