javascript - Vercel 上的 Next.js 部署失败

标签 javascript npm deployment next.js vercel

在 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播放列表的代码

最佳答案

正如评论所暗示的,错误很可能是由于大小写不同:navbar对比 Navbar .如果您更改为正确的大小写,它应该可以正常工作。
如果您在更改案例后仍然遇到问题(偶尔会发生),您还可以删除 git 中的缓存并重新提交更改。这很可能肯定会解决问题。 git 命令是共享的here ,我也在这里分享一下:

git rm -r --cached .
git add --all .
git commit -am "Fix casing discrepancies."
git push origin branch_name
在极少数情况下,上述解决方案也可能无法正常工作。这发生在我身上,在这种情况下实现绝对导入和模块路径别名解决了这个问题。对于这个解决方案,我推荐阅读 Next.js documentation .

关于javascript - Vercel 上的 Next.js 部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66438372/

相关文章:

javascript - 设置 reCAPTCHA Version 2 设置英语以外的另一种语言

javascript - Angularjs 仅在实际执行的指令中最后一次异步调用

javascript - 调用 node-oracledb 的 createPool 方法

reactjs - 没有找到任务运行器配置?

node.js - 如何自动链接本地 npm 包?

python - 如何将 python 代码部署到 Mac 上的应用程序中?

java - Eclipse 中的 Axis 插件是否使用 AdminClient 来部署 Web 服务?

javascript - crm2013 - 如何过滤特定实体的客户端查找

ruby-on-rails - rails : deploying first app - production mode

node.js - 在 NPM 包内声明全局命令