【问题标题】:React Dependency Tree Issue反应依赖树问题
【发布时间】:2022-01-25 19:49:27
【问题描述】:

谁能告诉我这里有什么不正确的地方?我正在尝试安装 mui 搜索栏组件。

npm i --save material-ui-search-bar

但是我确实收到了以下信息:

PS Z:\WebDev\ApplyWithin\frontend> npm i --save material-ui-search-bar
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: new@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!   peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.3
npm ERR!   node_modules/@material-ui/core
npm ERR!     peer @material-ui/core@"^4.0.0" from material-ui-search-bar@1.0.0
npm ERR!     node_modules/material-ui-search-bar
npm ERR!       material-ui-search-bar@"*" from the root project
npm ERR!     peer @material-ui/core@"^4.0.0" from @material-ui/icons@4.11.2
npm ERR!     node_modules/@material-ui/icons
npm ERR!       @material-ui/icons@"^4.11.2" from the root project
npm ERR!       1 more (material-ui-search-bar)
npm ERR!   2 more (react-dom, @material-ui/icons)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0" from material-ui-search-bar@1.0.0
npm ERR! node_modules/material-ui-search-bar
npm ERR!   material-ui-search-bar@"*" 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.

我的 package.json 是:

{
  "name": "new",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.7.0",
    "@emotion/styled": "^11.6.0",
    "@fontsource/roboto": "^4.5.1",
    "@material-ui/icons": "^4.11.2",
    "@mui/icons-material": "^5.2.4",
    "@mui/material": "^5.2.3",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "framer-motion": "^4.1.17",
    "gsap": "^3.9.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-intersection-observer": "^8.33.1",
    "react-scripts": "4.0.3",
    "react-typewriter-effect": "^1.1.0",
    "styled-components": "^5.3.3",
    "typewriter-effect": "^2.18.2",
    "web-vitals": "^1.0.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"
    ]
  }
}

这里有人知道吗?

【问题讨论】:

  • 为我工作,没有任何错误,只是警告。您是否尝试删除您的node_modules 和您的package-lock.json?之后,您可以重新安装依赖项。

标签: javascript node.js npm


【解决方案1】:

问题似乎与 material-ui-search-bar 的 peer dependency 有关。拥有对等依赖意味着你的包需要一个与安装你的包的人完全相同的依赖。

如您发布的错误中所述。它需要 react 版本 ^16.8.0 或更低版本才能运行。

但是在您的项目中,您指定了更大版本的 react - ^17.0.2。

你可以做的是降低你的反应版本。然后你应该能够安装上述包没有任何问题。

【讨论】:

    猜你喜欢
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多