如何解决上游依赖错误?我尝试过使用npm install --legacy-peer-deps和npm install --force,但这会引起更多问题。

3
这是我遇到的错误(可以有人解释一下为什么会出现这种错误,以及是否有更新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"
    ]
  }
}

我在Angular中遇到了相同类型的问题。你能解决吗?如果可以,请分享一下。 - Anand
@anand,这是因为react-tilt不支持最新版本的REACT。只需将react和react-dom的版本更改为16.14.0,并在终端中输入npm install,问题就会得到解决。 - NAMAN KOTHARI
2个回答

1
我遇到的问题是react-tilt在react 17版本下无法使用。
我尝试了使用' react-tilty'包,解决了我的问题:
npm i react-tilty

0

我遇到了同样的问题,不得不按照以下步骤解决。

  1. 进入Netlify中的项目,点击您的站点名称。
  2. 单击菜单右侧的网站设置按钮或选项卡。
  3. 在左侧窗格菜单上单击环境变量(新)。
  4. 单击添加变量按钮。
  5. 在键输入字段中键入CI,然后在值字段中键入false,然后单击创建变量按钮。
  6. 通过将键输入设置为NPM_FLAGS并将值输入设置为--legacy-peer-deps,重复从第4步开始的步骤以添加另一个环境变量。
  7. 完成后,单击页面顶部的部署选项卡菜单,然后单击触发部署按钮,并选择清除缓存和部署站点选项。

我从这里获得了link

除此之外,我还需要将netlify.toml文件添加到根目录,并添加以下行。
[build]
  command = "npm install --legacy-peer-deps --force && npm run build"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接