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.
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.
ls -la src/utils/ # check for format.ts vs Format.ts
# correct the import or rename the file to matchMake extensions resolvable
Add the extension to the import, or configure resolve.extensions so the build can append it.
// vite.config.ts
export default defineConfig({
resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'] },
})How to prevent it
- Run
vite buildin CI so disk-load failures surface before deploy. - Match import casing to filenames for case-sensitive runners.
- Keep
resolve.extensionsaligned with the extensions you omit in imports.