Dependencies are pre-bundled with esbuild once and cached, because a package shipping four hundred small CommonJS files would otherwise be four hundred browser requests.
$ npx vite
Pre-bundling dependencies:
lodash-es
axios
(this will be run only when your dependencies change)
$ ls node_modules/.vite/
axios.js lodash-es.js _metadata.json
# and when a dependency is not detected because it is
# imported dynamically from a string:
optimizeDeps: { include: ['some/deep/module'] }
The scan finds imports statically, so anything reached only through a computed path is missed and shows up as a page that reloads mid-navigation while Vite discovers and bundles it. Adding it to optimizeDeps.include is the fix and it is a list somebody has to maintain. The cache invalidates on lock file changes and occasionally needs deleting by hand, which is the first thing to try when Vite behaves inexplicably.