How to fix Next.js Vercel deployment module not found error
This answer worked for me: https://stackoverflow.com/a/55541435/3051080
TL;DR; update git cache
:
git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master
This error typically happens if you're accidentally committing node_modules
to your project's Git Repostiory.
Could you try to do the following?
- Ensure all changes have been committed and you have a clean directory.
- Run
rm -rf node_modules
(or delete the folder on Windows). - Run
git add -A
thengit commit -m "Remove all module files"
. - Add
node_modules
to your.gitignore
file (and save). - Run
git add -A
thengit commit -m "Update ignored files"
. - Verify your directory is completely clean via
git status
. - Then, run
git push
. This deployment should work on Vercel. - Finally, re-run
npm i
oryarn
depending on your package manager to get your local copy working.
I had to edit my package.json
to use the next
binary that ships in the node_modules/next
directory:
"scripts": {
"start": "node_modules/next/dist/bin/next start -p $PORT"
}
Not the most elegant fix but it works.