Skip to content
Latchkey

Vite "Could not load <file> (imported by <file>)" - Fix in CI

During vite build, Rollup resolved an import to a path but then failed to read the file from disk. The specifier mapped to something that does not exist - a missing file, a casing mismatch, or an extension the resolver did not append.

What this error means

The build fails with Could not load <path> (imported by <file>): ENOENT: no such file or directory. It surfaces in the production Rollup pass, so vite dev may have tolerated it.

vite output
error during build:
Could not load /app/src/utils/format (imported by src/App.tsx):
ENOENT: no such file or directory, open '/app/src/utils/format'

Common causes

File missing or wrong case

The imported file does not exist at that path, or its casing differs from the import. Case-sensitive Linux runners fail where macOS did not.

Missing extension the build does not infer

Importing without an extension where the resolver cannot guess it (or an asset import without a matching plugin) leaves Rollup with a path it cannot read.

How to fix it

Verify the file and its exact case

Confirm the target exists at the imported path with matching casing.

Terminal
ls -la src/utils/   # check for format.ts vs Format.ts
# correct the import or rename the file to match

Make extensions resolvable

Add the extension to the import, or configure resolve.extensions so the build can append it.

vite.config.ts
// vite.config.ts
export default defineConfig({
  resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'] },
})

How to prevent it

  • Run vite build in CI so disk-load failures surface before deploy.
  • Match import casing to filenames for case-sensitive runners.
  • Keep resolve.extensions aligned with the extensions you omit in imports.

Frequently asked questions

What causes ""Could not load ... (imported by)""?
The imported file does not exist at that path, or its casing differs from the import. Case-sensitive Linux runners fail where macOS did not.
How do I fix "Could not load ... (imported by)"?
Confirm the target exists at the imported path with matching casing.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card