Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing Next.js deployment on Vercel

While deploying project on vercel getting this issue ,
fileName: comps/Navbar.js
imported as import Navbar from "./Navbar";

16:36:51    ModuleNotFoundError: Module not found: Error: Can't resolve '../comps/navbar' in '/vercel/workpath0/pages'
16:36:51    > Build error occurred
16:36:51    Error: > Build failed because of webpack errors
16:36:51        at /vercel/workpath0/node_modules/next/dist/build/index.js:15:918
16:36:51        at processTicksAndRejections (internal/process/task_queues.js:93:5)
16:36:51        at async /vercel/workpath0/node_modules/next/dist/build/tracer.js:1:525
16:36:51    npm ERR! code ELIFECYCLE
16:36:51    npm ERR! errno 1
16:36:51    npm ERR! [email protected] build: `next build`
16:36:51    npm ERR! Exit status 1
16:36:51    npm ERR! 
16:36:51    npm ERR! Failed at the [email protected] build script.
16:36:51    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
16:36:51    npm ERR! A complete log of this run can be found in:
16:36:51    npm ERR!     /vercel/.npm/_logs/2021-03-02T11_06_51_966Z-debug.log
16:36:51    Error: Command "npm run build" exited with 1
16:36:56    Done with "package.json"

Code from net ninja next js playlist

like image 638
Piyush Gupta Avatar asked Oct 29 '25 04:10

Piyush Gupta


1 Answers

As the comment suggests, the error is most likely due to casing being different: navbar vs Navbar. If you change to correct casing, it should work fine.

If you still face the problem even after changing the cases (which happens occasionally), you could also remove caching in git and re-commit the changes. This will most likely fix the issue for sure. The git commands are shared here, I'll share it here as well:

git rm -r --cached .
git add --all .
git commit -am "Fix casing discrepancies."
git push origin branch_name

In some rare cases the solution above also might not work as well. This happened to me, and in such case implementing Absolute Imports and Module path aliases fixed the issue. For this solution, I recommend reading the Next.js documentation.

like image 88
Will Kim Avatar answered Oct 31 '25 19:10

Will Kim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!