Next.js在Vercel上部署失败



在vercel上部署项目时得到此问题,
fileName: 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 playlist

如注释所示,错误很可能是由于大小写不同:navbarvsNavbar。如果您更改为正确的大小写,应该可以正常工作。

如果在更改了案例之后仍然面临这个问题(这种情况偶尔会发生),您也可以删除git中的缓存并重新提交更改。这很可能会解决这个问题。git命令在这里共享,我也将在这里共享:

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

在一些罕见的情况下,上面的解决方案也可能不起作用。这种情况发生在我身上,在这种情况下,实现绝对导入和模块路径别名解决了这个问题。对于这个解决方案,我建议阅读Next.js文档。

相关内容

  • 没有找到相关文章

最新更新