Vite "Rollup failed to resolve import" build error in CI
During vite build, Rollup walks the real import graph and an import does not resolve to any file or installed package. The dev server uses a more lenient resolver, so this often only fails in CI at build time.
What this error means
vite build stops with "[vite]: Rollup failed to resolve import X from Y. This is most likely unintended because it can break your application at runtime." The dev server ran fine for the same code.
[vite]: Rollup failed to resolve import "lodash/throttle" from "src/utils/scroll.ts".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`Common causes
The dependency is missing from the lockfile
The import points at a package that is present locally but not in package.json/lockfile, so a clean npm ci in CI never installs it and Rollup cannot resolve it.
A path that differs only by case
macOS is case-insensitive but the Linux runner is not, so ./Components/Button resolves locally and 404s in CI.
How to fix it
Add the real dependency and reinstall cleanly
- Confirm the package is a real dependency, then add it to
package.json. - Run
npm ciso the lockfile install matches CI exactly. - Re-run
vite buildto confirm Rollup resolves the import.
npm install lodash
npm ci
npx vite buildFix case-sensitive import paths
Make every relative import match the file name on disk exactly, including case, so the Linux runner resolves it.
// file is src/components/Button.tsx
import Button from './components/Button'How to prevent it
- Run
npm ci(notnpm install) in CI so installs match the lockfile. - Keep import path casing identical to the file on disk.
- Run
vite buildlocally before pushing, not only the dev server.