reactjs 升级到MUI版本5的依赖性问题

2jcobegt  于 2023-02-15  发布在  React
关注(0)|答案(2)|浏览(138)

我正在尝试将MUI v4升级到MUI v5,我已经阅读了迁移到v5 here的文档。
我在运行npm update时收到此错误消息

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: placemaker@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@"^17.0.0" from @mui/styles@5.11.7
npm ERR! node_modules/@mui/styles
npm ERR!   @mui/styles@"^5.10.16" 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!
npm ERR! For a full report see:

日志文件:

C:\Users\...\...\...\file.log

# npm resolution error report

While resolving: app@0.1.0
Found: react@18.2.0
node_modules/react
  react@"^18.2.0" from the root project

Could not resolve dependency:
peer react@"^17.0.0" from @mui/styles@5.11.7
node_modules/@mui/styles
  @mui/styles@"^5.10.16" from the root project

Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

我的package.json依赖项

"dependencies": {
    "@auth0/auth0-react": "^1.12.0",
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@mui/icons-material": "^5.10.16",
    "@mui/material": "^5.10.16",
    "@mui/styles": "^5.10.16",
    "@mui/x-data-grid": "^5.17.13",
    "@mui/x-date-pickers": "^5.0.9",
    "@reduxjs/toolkit": "^1.9.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/multer": "^1.4.7",
    "@types/node": "^16.18.3",
    "@types/pg": "^8.6.5",
    "@types/react": "^18.0.25",
    "@types/react-dom": "^18.0.9",
    "@types/react-redux": "^7.1.24",
    "auth0": "^3.1.1",
    "autosuggest-highlight": "^3.3.4",
    "axios": "^0.27.2",
    "cors": "^2.8.5",
    "dayjs": "^1.11.6",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "express-oauth2-jwt-bearer": "^1.2.0",
    "express-promise-router": "^4.1.1",
    "helmet": "^6.0.1",
    "multer": "^1.4.5-lts.1",
    "nodemon": "^2.0.20",
    "pg": "^8.8.0",
    "pg-format": "^1.0.4",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.40.0",
    "react-redux": "^8.0.5",
    "react-router-dom": "^6.4.3",
    "react-select": "^5.6.1",
    "socket.io": "^4.5.4",
    "socket.io-client": "^4.5.4",
    "typescript": "^4.9.3",
    "uuid": "^8.3.2",
    "web-vitals": "^2.1.4"
  },
  "devDependencies": {
    "@types/autosuggest-highlight": "^3.2.0",
    "@types/cors": "^2.8.12",
    "@types/dotenv": "^8.2.0",
    "@types/google.maps": "^3.50.5",
    "@types/helmet": "^4.0.0",
    "@types/uuid": "^8.3.4",
    "concurrently": "^7.6.0",
    "react-scripts": "5.0.1"
  },

不知道如何解决这个问题,它似乎日志告诉我,react@^17.0.0应该工作,我运行的版本18。
npm auidt --production提供以下信息:

# npm audit report

json5  2.0.0 - 2.2.1
Severity: high
Prototype Pollution in JSON5 via Parse Method - https://github.com/advisories/GHSA-9c47-m6qq-7p4h
fix available via `npm audit fix`
node_modules/json5

1 high severity vulnerability
ngynwnxp

ngynwnxp2#

事实证明,我没有彻底阅读MUI文档,我不得不:

  • npm uninstall @mui/style
  • npm i @mui/system

替换依赖于@mui/style的旧代码
这消除了版本不匹配。
我尝试了不同的方法,即NPM更新--强制/ NPM审计修复--强制,这只会使它变得更糟,因为降级到不同的包会产生更多的漏洞。
感谢所有的帮助!将接受sancelots的答案虽然我没有尝试过,它似乎是一个初学者友好的解决方案

相关问题