Skip to content
Latchkey

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
[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

  1. Confirm the package is a real dependency, then add it to package.json.
  2. Run npm ci so the lockfile install matches CI exactly.
  3. Re-run vite build to confirm Rollup resolves the import.
Terminal
npm install lodash
npm ci
npx vite build

Fix case-sensitive import paths

Make every relative import match the file name on disk exactly, including case, so the Linux runner resolves it.

src/app.tsx
// file is src/components/Button.tsx
import Button from './components/Button'

How to prevent it

  • Run npm ci (not npm install) in CI so installs match the lockfile.
  • Keep import path casing identical to the file on disk.
  • Run vite build locally before pushing, not only the dev server.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →