Skip to content
Latchkey

Astro "Could not resolve" import during build in CI

Astro uses Vite/Rollup to bundle. "Could not resolve X" means the importer references a path or package the build cannot map to a file on the runner. The message names the importing file and the missing target.

What this error means

The build fails with Could not resolve "..." pointing at an import in a .astro, .ts, or framework component file.

astro
[ERROR] Could not resolve "../lib/api" from "src/pages/blog/[slug].astro"
    file: /home/runner/work/site/src/pages/blog/[slug].astro

Common causes

A wrong path, casing, or missing extension

The relative path or alias points at a file that does not exist at that exact path and casing on the Linux runner.

A dependency not installed on the runner

A bare package import resolves locally but the package was not installed in CI (a devDependency skipped or a dirty local tree).

How to fix it

Fix the path or install the package

  1. Confirm the target file exists at the exact path and casing used.
  2. For a package, add it to dependencies and run a clean install.
  3. Re-run the build after the change.
Terminal
npm ci
npm run build

Configure a path alias if you use one

Define aliases in tsconfig (and Vite resolve.alias if needed) so @/ style imports resolve during build.

tsconfig.json
// tsconfig.json
{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }

How to prevent it

  • Match import casing to filenames on case-sensitive runners.
  • Declare every imported package in dependencies.
  • Keep tsconfig and Vite aliases consistent.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →