如何修复“未找到”模块。部署nextJS应用程序的错误
我正在尝试部署我的nextjs应用程序以netlify,但它一直显示错误找不到模块:无法解析'../components/home/home'in'/opt/opt/build/repo/pem' in Build Log。
但是本地构建命令没有导致任何错误。
我在Netlify中的构建设置是:
基本目录 未设置
构建命令 npm运行构建
发布目录 .next
构建 活动
部署日志包含此错误消息
7:06:59 AM: ./pages/index.js
7:06:59 AM: Module not found: Can't resolve '../components/home/home' in '/opt/build/repo/pages'
7:06:59 AM: > Build failed because of webpack errors
7:06:59 AM:
7:06:59 AM: ────────────────────────────────────────────────────────────────
7:06:59 AM: "build.command" failed
7:06:59 AM: ────────────────────────────────────────────────────────────────
7:06:59 AM:
7:06:59 AM: Error message
7:06:59 AM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
7:06:59 AM:
7:06:59 AM: Error location
7:06:59 AM: In Build command from Netlify app:
7:06:59 AM: npm run build
7:06:59 AM:
7:06:59 AM: Resolved config
7:06:59 AM: build:
7:06:59 AM: command: npm run build
7:06:59 AM: commandOrigin: ui
7:06:59 AM: environment:
7:06:59 AM: - NEXT_PRIVATE_TARGET
7:06:59 AM: publish: /opt/build/repo/.next
7:06:59 AM: publishOrigin: ui
7:06:59 AM: plugins:
7:06:59 AM: - inputs: {}
7:06:59 AM: origin: ui
7:06:59 AM: package: '@netlify/plugin-nextjs'
7:06:59 AM: Caching artifacts
I'm trying to deploy my NextJS App to Netlify but it keeps showing the errorModule not found: Can't resolve '../components/home/home' in '/opt/build/repo/pages'
in the build log.
But locally the build command didn't result in any errors.
My build settings in Netlify are:
Base directory Not set
Build command npm run build
Publish directory .next
Builds Active
Deploy log contains this error message
7:06:59 AM: ./pages/index.js
7:06:59 AM: Module not found: Can't resolve '../components/home/home' in '/opt/build/repo/pages'
7:06:59 AM: > Build failed because of webpack errors
7:06:59 AM:
7:06:59 AM: ────────────────────────────────────────────────────────────────
7:06:59 AM: "build.command" failed
7:06:59 AM: ────────────────────────────────────────────────────────────────
7:06:59 AM:
7:06:59 AM: Error message
7:06:59 AM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
7:06:59 AM:
7:06:59 AM: Error location
7:06:59 AM: In Build command from Netlify app:
7:06:59 AM: npm run build
7:06:59 AM:
7:06:59 AM: Resolved config
7:06:59 AM: build:
7:06:59 AM: command: npm run build
7:06:59 AM: commandOrigin: ui
7:06:59 AM: environment:
7:06:59 AM: - NEXT_PRIVATE_TARGET
7:06:59 AM: publish: /opt/build/repo/.next
7:06:59 AM: publishOrigin: ui
7:06:59 AM: plugins:
7:06:59 AM: - inputs: {}
7:06:59 AM: origin: ui
7:06:59 AM: package: '@netlify/plugin-nextjs'
7:06:59 AM: Caching artifacts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决我自己问题的解决方案。
它与Windows Case不敏感有关,而NetLify使用Linux服务器!
因此,我不得不重命名所有下降的命名组件中的大写组件,并且起作用。
这些文章对我有所帮助。
https://github.com/github.com/vercel/next.js/next.js/discussions/16179
更改git中的文件名的资本化
我希望它将对未来的人有帮助。
I have found the solution to my own problem.
It's related to Windows case insensitive whereas Netlify uses Linux servers which are!
So, I had to rename all my lowercased named components to uppercase and it worked.
These articles have helped me.
https://github.com/vercel/next.js/discussions/16179
Changing capitalization of filenames in Git
I hope it will help someone in the future.