【问题标题】:React app Heroku deployment tree dependency errorReact app Heroku部署树依赖错误
【发布时间】:2022-08-13 23:44:21
【问题描述】:

我正在尝试将我的反应应用程序部署到 Heroku,但我一直陷入这个问题。我怎样才能找到解决这种情况的方法?

这是我的 package.json:

{
  \"name\": \"pworkflow\",
  \"version\": \"0.1.0\",
  \"private\": true,
  \"dependencies\": {
    \"@emotion/react\": \"^11.9.3\",
    \"@emotion/styled\": \"^11.9.3\",
    \"@fullcalendar/daygrid\": \"^5.11.0\",
    \"@fullcalendar/list\": \"^5.11.0\",
    \"@fullcalendar/react\": \"^5.11.1\",
    \"@fullcalendar/timegrid\": \"^5.11.0\",
    \"@material-ui/core\": \"^4.12.4\",
    \"@material-ui/icons\": \"^4.11.3\",
    \"@mui/material\": \"^5.9.0\",
    \"@mui/x-date-pickers\": \"^5.0.0-beta.1\",
    \"@testing-library/jest-dom\": \"^5.16.4\",
    \"@testing-library/react\": \"^13.3.0\",
    \"axios\": \"^0.27.2\",
    \"date-fns\": \"^2.28.0\",
    \"moment\": \"^2.29.4\",
    \"react\": \"^18.2.0\",
    \"react-dom\": \"^18.2.0\",
    \"react-hot-toast\": \"^2.3.0\",
    \"react-router-dom\": \"^6.3.0\",
    \"react-scripts\": \"^2.1.3\",
    \"react-select\": \"^5.4.0\",
    \"universal-cookie\": \"^4.0.4\",
    \"web-vitals\": \"^2.1.4\"
  },
  \"scripts\": {
    \"start\": \"react-scripts start\",
    \"build\": \"npm install --legacy-peer-deps\",
    \"test\": \"react-scripts test\",
    \"eject\": \"react-scripts eject\"
  },
  \"eslintConfig\": {
    \"extends\": [
      \"react-app\",
      \"react-app/jest\"
    ]
  },
  \"browserslist\": {
    \"production\": [
      \">0.2%\",
      \"not dead\",
      \"not op_mini all\"
    ],
    \"development\": [
      \"last 1 chrome version\",
      \"last 1 firefox version\",
      \"last 1 safari version\"
    ]
  },
  \"engines\" : { 
    \"npm\" : \">=6.14.9\",
    \"node\" : \"<=14.x.x\"
  }
}

Heroku 构建日志上的错误消息:

   Installing node modules (package.json)
   npm ERR! code ERESOLVE
   npm ERR! ERESOLVE unable to resolve dependency tree
   npm ERR! 
   npm ERR! While resolving: pworkflow@0.1.0
   npm ERR! Found: react@18.2.0
   npm ERR! node_modules/react
   npm ERR!   react@\"^18.2.0\" from the root project
   npm ERR! 
   npm ERR! Could not resolve dependency:
   npm ERR! peer react@\"^16.8.0 || ^17.0.0\" from @material-ui/core@4.12.4
   npm ERR! node_modules/@material-ui/core
   npm ERR!   @material-ui/core@\"^4.12.4\" from the root project
   npm ERR! 
   npm ERR! Fix the upstream dependency conflict, or retry
   npm ERR! this command with --force, or --legacy-peer-deps
   npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
   npm ERR! 
   npm ERR! See /tmp/npmcache.dFf83/eresolve-report.txt for a full report.
   npm ERR! A complete log of this run can be found in:
   npm ERR!     /tmp/npmcache.dFf83/_logs/2022-08-13T02_48_53_929Z-debug-0.log

当我在我的机器上构建它时,我总是必须使用下一个命令--legacy-peer-deps,否则它会失败。

但我不知道如何让 Heroku 运行该命令而不是标准命令。

标签: reactjs npm heroku deployment build


【解决方案1】:

我解决了在项目的根目录中创建一个 .npmrc 包含下一行: legacy-peer-deps=true

取自Strapi + Heroku deployment failed:npm ERR! code ERESOLVE

Hard Monkey PC 答案

【讨论】:

  • 遇到同样的麻烦,节省了很多时间,非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-24
  • 1970-01-01
  • 2017-09-21
  • 1970-01-01
  • 2019-01-21
  • 2021-10-13
  • 2019-06-07
相关资源
最近更新 更多