# Vite build "[rollup] Could not resolve import" (external) in CI

> Fix Rollup "Could not resolve" during a Vite build in CI - an import has no installed package and is not declared external, so the bundler cannot resolve it.

Source: https://latchkey.dev/learn/node-js/vite-build-rollup-could-not-resolve-external-in-ci  
Updated: 2026-06-26

During `vite build`, Rollup could not resolve an import. Either the package is missing, the path is wrong, or it is a Node built-in that should be marked external rather than bundled.

## Diagnose it: the shell in CI is not your shell

Package scripts run under a different shell, a different PATH, and a non-interactive environment on a runner. Most scripts that fail only in CI are relying on something the login shell gave them locally: a tool on PATH, an environment variable from a dotfile, or a TTY.

```Terminal
# what the script can actually see
npm run env | grep -E "^(PATH|NODE_ENV|CI)=" 

# is the binary on PATH for the script, not just for you?
npm exec -- which <tool> || echo "not resolvable from npm scripts"

# run the exact script with tracing
sh -x -c "$(node -p "require('./package.json').scripts.build")"
```

> A tool installed globally on your machine but only a devDependency in the repo works locally and fails in CI. Call it through `npm exec` or a `node_modules/.bin` path rather than assuming it is on PATH.

## Make failures fail the job

A multi-command script can report success while a middle command failed, which produces the worst kind of CI result: a green build that shipped something broken.

```.github/workflows/ci.yml
# pipefail is NOT set by default in every runner shell
- name: Build
  shell: bash
  run: |
    set -euo pipefail
    npm run build | tee build.log
```

> Without `pipefail`, the exit status of a pipeline is the status of the LAST command, so `failing-command | tee log` reports success. Piping build output to a log file is exactly where this bites.

## FAQ

### What causes Vite build "[rollup] could not resolve import" (external) in CI?

There are 2 common causes: a missing dependency or wrong path and a node built-in being bundled for the browser. The imported package is not installed, or the relative path does not exist in the build context.

### How do I fix Vite build "[rollup] could not resolve import" (external) in CI?

There are 2 fixes depending on which cause you have: install the dependency or fix the path and mark legitimate externals. Work through them in order, since the first is the most common.

### What does Vite build "[rollup] could not resolve import" (external) in CI actually mean?

A vite build aborts with [rollup] Could not resolve "x" from ....

### How do I stop Vite build "[rollup] could not resolve import" (external) in CI happening again?

Run the production build (not just dev) in CI to catch resolution gaps. The prevention section lists 3 changes that keep it from recurring.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
