npm installing dependecies error,no luck with --force or --legacy-peer-deps

643ylb08  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(82)

我开始一个新的p[roject/following with react,当我试图安装视频中提到的依赖项时,我遇到了这个错误,我不知道如何解决自己。
相关性和错误消息如下:

npm install @material-ui/core @material-ui/icons @material-ui/lab @react-google-maps/api axios google-dash-map-react
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: travel_app@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@"*" 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\pogibro\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\pogibro\AppData\Local\npm-cache\_logs\2023-01-15T11_16_51_369Z-debug-0.log

字符串
以下是我的package.json文件:

{
  "name": "travel_app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "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"
    ]
  }
}


我试图找到类似的错误,但没有运气。尝试了-froce和-legacy-peer-deps,但没有工作!

vcirk6k6

vcirk6k61#

@material-ui/core@4.12.4与React 18.x不兼容,已弃用。请使用MUI v5
让我们检查MUI v4的对等依赖关系:

$ npm view @material-ui/core@4.12.4 peerDependencies
{
  '@types/react': '^16.8.6 || ^17.0.0',
  react: '^16.8.0 || ^17.0.0',
  'react-dom': '^16.8.0 || ^17.0.0'
}

字符串
正如您所看到的,MUI v4使用React ^16.8.0React ^17.0.0。但是在你的项目中,React版本是^18.2.0,这是不兼容的。
相关问题:

MUI v5.6.0开始支持React 18,最新版本是5.13.6(直到2023.7.4)。您可以安装最新版本。

相关问题