skip to content
Just Change Direction

How to fix the "Cannot find module" error in Vercel

/ 1 min read

I am a huge fan of Vercel and owe a lot of my career to NextJS. However, I somehow seem to always run into issues deploying really simple websites with them (I didn’t update my personal site for over a year as I couldn’t fix an issue that only broke in their CI).

Today’s issue was that I kept getting @blackhaj/website:build: src/layouts/base.astro:2:22 - error ts(2307): Cannot find module './document.astro' or its corresponding type declarations. errors when deploying a 3 page Astro site 😫.

Turns out that the issue was likely caused by changing the case of the file name from Document.astro to document.astro. The import and the filename were correct but it kept failing on Vercel (despite working when building locally).

Thanks to this Stackoverflow solution, this command fixes it:

Terminal window
git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push