Vite optimizeDeps "Failed to resolve entry for package" - Fix in CI
Vite pre-bundles dependencies with esbuild and could not find a usable entry point for one of them. The package's exports/main map does not point at a file Vite can load, or the dependency must be explicitly included or excluded from optimization.
What this error means
The dev server or vite build fails during dep optimization with Failed to resolve entry for package "<pkg>". The package may have incorrect main/module/exports specified in its package.json. It is deterministic and names the package.
Failed to resolve entry for package "some-lib". The package may have incorrect
main/module/exports specified in its package.json.
at packageEntryFailure (vite/dist/node/chunks/dep.js)Common causes
Broken package entry map
The dependency declares an exports/main/module that points at a missing file or a condition Vite does not resolve, so pre-bundling has no entry to start from.
Dependency needs explicit include/exclude
A package shipped as CJS, or one that re-exports many internal modules, may need to be listed in optimizeDeps.include (to be pre-bundled) or exclude (to be left alone) for Vite to handle it correctly.
How to fix it
Force-include or exclude the dependency
Tell Vite how to treat the problematic package during optimization.
// vite.config.ts
export default defineConfig({
optimizeDeps: {
include: ['some-lib'], // pre-bundle a CJS/awkward dep
exclude: ['some-esm-only-lib'], // skip optimization for a pure-ESM dep
},
})Work around a broken upstream entry
- Inspect the dependency's
package.jsonexports/mainand confirm the target file exists. - If the package is genuinely broken, alias the import to the real file, or pin a version with a correct entry map.
- Report the broken entry upstream so the fix is durable.
How to prevent it
- Pin dependency versions so an entry-map regression cannot drift in.
- Use
optimizeDeps.include/excludefor known-awkward packages. - Run
vite buildin CI so pre-bundle failures surface before deploy.