建置失败,因为在heroku中部署Next.js时发生webpack错误

s8vozzvw  于 2022-11-13  发布在  Webpack
关注(0)|答案(1)|浏览(127)

我正在尝试使用heroku CLI将Next,js应用程序部署到heroku。运行git push heroku master时遇到以下问题。以下是我当前设置中的package.json文件。请帮助。我已搜索此问题,但无法找到任何与之相关的内容。我可以在本地计算机中构建next.js应用程序,但无法在heroku中部署。

封装. json

{
"name": "XXXX-ecommerce",
"version": "0.1.0",
"engines": {
  "node": "18.x",
  "npm": "7.x"
},
"private": true,
"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start",
  "lint": "next lint",
  "heroku-postbuild": "npm run build",
  "test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
  "@apollo/client": "^3.7.0",
"@nacelle/react-yotpo": "^8.0.0",
"axios": "^1.1.3",
"cookie": "^0.5.0",
"cookie-cutter": "^0.2.0",
"graphql": "^16.6.0",
"lodash": "^4.17.21",
"lodash.filter": "^4.6.0",
"lodash.uniqby": "^4.7.0",
"next": "12.3.1",
"react": "18.2.0",
"react-collapsible": "^2.10.0",
"react-dom": "18.2.0",
"react-rating": "^2.0.5",
"swiper": "^8.4.2"
},
"devDependencies": {
    "eslint": "8.24.0",
    "eslint-config-next": "12.3.1"
}
}

Heroko构建日志:

info  - Creating an optimized production build...
 Failed to compile.
 ./components/card.js
 Module not found: Can't resolve 'lodash.uniqBy' in '/tmp/build_54073365/components'
 Import trace for requested module:
 ./components/card.js
 ./components/productSlider.js
 ./pages/products/[id].js
 Module not found: Can't resolve 'lodash.uniqBy' in 
 '/tmp/build_54073365/pages/products'
   > Build failed because of webpack errors
   -----> Build failed
   
   We're sorry this build is failing! You can troubleshoot common issues here:
   https://devcenter.heroku.com/articles/troubleshooting-node-deploys
   
   If you're stuck, please submit a ticket so we can help:
   https://help.heroku.com/
   
   Love,
   Heroku
   
  !     Push rejected, failed to compile Node.js app.
  !     Push failed
vddsk6oq

vddsk6oq1#

软件包的名字是lodash.uniqby(全部小写)。检查你的导入,看起来你的一个组件中有uniqBy(大写的B)。这可能是在本地工作的,因为macOS和Windows有不区分大小写的文件系统,所以它可以在本地工作,但如果部署到运行Linux的机器上,比如Heroku上,它就不能。

相关问题