在Vercel上部署Next.js失败

4
在部署项目到 Vercel 时遇到以下问题:
文件名:comps/Navbar.js
被导入为: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! friendlist@0.1.0 build: `next build`
16:36:51    npm ERR! Exit status 1
16:36:51    npm ERR! 
16:36:51    npm ERR! Failed at the friendlist@0.1.0 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"

来自Net Ninja Next.js播放列表的代码


1
大小写可能有问题,是navbar还是Navbar - juliomalves
1
请查看以下链接以了解如何解决“找不到模块”错误:https://vercel.com/support/articles/how-do-i-resolve-a-module-not-found-error?query=module%20 - paulogdm
1
哦,是的,它刚刚解决了我的问题。我在推送代码时使用了“Navbar”和“navbar”,但git并没有将其视为更改。因此,我直接从GitHub更改了文件名,并成功部署了代码。感谢@paulogdm和juliomalves。 - Piyush Gupta
1个回答

6

正如评论所示,错误很可能是由于大小写不同造成的:navbarNavbar。如果更正大小写,应该可以正常工作。

如果在更改大小写后仍然遇到问题(这有时会发生),您还可以在git中删除缓存并重新提交更改。这很可能会确保修复问题。git命令在此处共享,我也在此处分享一下:

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

在一些罕见情况下,上述解决方案可能也不起作用。这种情况发生在我身上过,解决办法是实施绝对导入和模块路径别名。针对这种情况,我建议阅读 Next.js 的文档

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接