Astro shows “Could not import file” when an import in a component, page or layout points at a path that does not resolve. The usual causes are a typo, wrong letter case, a missing .astro extension, or a path alias that is not defined in tsconfig.json. Fix the path so it matches the real file and the error clears on the next reload.
Key Takeaways
- The message names the exact import that failed; search your code for it.
.astroimports need the extension:../components/Card.astro.- Letter case matters on Linux and in most CI builds, even if macOS ignores it.
- Aliases like
@/componentsonly work ifcompilerOptions.pathsdefines them.- For packages, the fix is usually
npm install.
The error
In astro dev the error overlay shows:
Could not import file.
Could not import `../components/Hedaer.astro`.
Hint: This is often caused by a typo in the import path. Please make sure the file exists.
Astro rewrites Vite’s lower-level “Failed to load url” error into this one, so the path in backticks is exactly what your code asked for.
Why it happens
Vite resolves every import relative to the file that contains it. If nothing exists at that path, the module cannot load. Common versions of the mistake:
- Typo or moved file.
Hedaer.astro, or a component you moved fromsrc/components/tosrc/components/ui/. - Wrong depth. A page in
src/pages/blog/needs../../components/, not../components/. - Missing extension. TypeScript files resolve without an extension,
.astrofiles do not. - Case mismatch.
card.astroimported asCard.astroworks on a case-insensitive macOS disk and fails on Linux. - Undefined alias.
@/lib/postswithout a matchingpathsentry.
Fix the path
Check the file really exists where the import points:
# Terminal
ls src/components/
grep -rn "Hedaer" src/
Then correct the import, including the extension:
---
// src/pages/blog/index.astro
import Header from '../../components/Header.astro';
---
<Header />
If you renamed a file only by case, Git on macOS may not record the change. Rename it explicitly so CI sees the new name:
# Terminal
git mv src/components/card.astro src/components/Card.astro
Fix a path alias
Astro reads path aliases from tsconfig.json. Define the alias there:
{
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
Restart astro dev after changing tsconfig.json. Our TypeScript config guide covers aliases in more detail, and the folder structure docs show where each kind of file usually lives.
Fix a missing package
If the path is a package name (import confetti from 'canvas-confetti'), the package is not installed in this project:
# Terminal
npm install canvas-confetti
After a fresh clone, run npm install before npm run dev. If you started from one of our Astro themes, this is the most common cause on first run. For errors where the file exists but cannot be used in the browser, see fix: module is server-only. The Astro imports reference lists which file types can be imported.
FAQ
Why does my Astro import work locally but fail on deploy?
Almost always letter case. macOS treats Card.astro and card.astro as the same file; Linux build servers do not. Make the import match the file name exactly and commit the rename with git mv.
Do I need the .astro extension in imports?
Yes. Astro components must be imported with .astro. TypeScript and JavaScript files can omit their extension.
Why does my @/ alias not work in Astro?
The alias is not defined in tsconfig.json, or the dev server was not restarted after adding it. Add a paths entry under compilerOptions and restart astro dev.