reactjs 我如何修复上游依赖性错误?我已经尝试执行npm install --legacy-peer-deps和npm install --force,但这会导致进一步的问题

qmb5sa22  于 2023-04-11  发布在  React
关注(0)|答案(2)|浏览(156)

这是我得到的错误(有人能解释一下为什么会发生这样的错误,以及是否有方法将npm更新到我的react版本。

PS C:\Naman Kothari\udemy course\react\thelastone> npm i react-tilt
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: thelastone@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0-beta || ^16.0.0" from react-tilt@0.1.4
npm ERR! node_modules/react-tilt
npm ERR!   react-tilt@"*" 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 C:\Users\namrata kothari\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\namrata kothari\AppData\Local\npm-cache\_logs\2021-04-24T15_15_44_230Z-debug.log

这是我的package.json(主要是安装create-react-app npm时默认创建的所有包)。

{
  "name": "thelastone",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "tachyons": "^4.12.0",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "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"
    ]
  }
}
yhuiod9q

yhuiod9q1#

我遇到的问题是react-tilt不适用于react的17版本。
我试着用“react-tilty”包解决了我的问题:

npm i react-tilty
izj3ouym

izj3ouym2#

我也遇到了同样的问题,必须按照这些步骤来解决。
1.转到Netlify中的项目,然后单击站点名称。
1.单击菜单最右侧的站点设置按钮或选项卡。
1.单击左窗格菜单上的Environment variables(New)。
1.单击“添加变量”按钮。
1.在键输入字段中键入CI,然后在值字段中键入false,然后单击Create variable按钮。
1.重复从步骤4开始的步骤,通过将键输入设置为NPM_FLAGS并将值输入设置为--legacy-peer-deps来添加另一个Environment变量。
1.完成后,单击页面顶部的Deploys选项卡菜单,然后单击Triggerdeploy按钮,并选择Clearcacheanddeploy site选项。
我从这个link得到的
除此之外,我还必须将netlify.toml文件添加到根目录,并添加这几行。

[build]
  command = "npm install --legacy-peer-deps --force && npm run build"

相关问题