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.
[ERROR] Could not resolve "../lib/api" from "src/pages/blog/[slug].astro"
file: /home/runner/work/site/src/pages/blog/[slug].astroCommon 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
- Confirm the target file exists at the exact path and casing used.
- For a package, add it to dependencies and run a clean install.
- Re-run the build after the change.
npm ci
npm run buildConfigure 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
{ "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.