无法在react中安装@mui/x-data-grid


npm install @mui/x-data-grid

抛出错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: highradius@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR!   peer react@"^17.0.0 || ^18.0.0" from @mui/material@5.6.0
npm ERR!   node_modules/@mui/material
npm ERR!     @mui/material@"^5.6.0" from the root project
npm ERR!     peer @mui/material@"^5.2.8" from @mui/x-data-grid@5.8.0
npm ERR!     node_modules/@mui/x-data-grid
npm ERR!       @mui/x-data-grid@"*" from the root project
npm ERR!   4 more (@emotion/react, @emotion/styled, react-dom, @mui/system)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.2" from @mui/x-data-grid@5.8.0
npm ERR! node_modules/@mui/x-data-grid
npm ERR!   @mui/x-data-grid@"*" 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:Users1karAppDataLocalnpm-cacheeresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:Users1karAppDataLocalnpm-cache_logs2022-04-06T12_50_46_543Z-debug-0.log

我认为依赖关系中存在一些版本不匹配。反应迟钝,无法理解依赖关系。请给出一个逐步解决此错误的过程。

{
"name": "highradius",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/base": "^5.0.0-alpha.75",
"@mui/material": "^5.6.0",
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.0",
"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"
]
}
}

这是package.json文件。我试着安装npm install@mui/material@memotion/reflect@memotion/styled,它安装成功了,现在我正在尝试安装数据网格,但它显示了这个错误。

npm i @mui/x-data-grid --legacy-peer-deps

使用这个安装解决了我的问题。

根据@mui/x-data-grid的文档,这段代码似乎应该解决的问题

"peerDependencies": {
"@mui/material": "^5.0.0",
"react": "^17.0.0"
},

在npm命令末尾添加--legacy peer deps,如下所示👇

npm i @mui/x-data-grid --legacy-peer-deps

尝试npm install @mui/x-data-grid --legacy-peer-deps,它会正常工作。

顶级答案的纱线版本

yarn add @mui/x-data-grid --ignore-optional

相关内容

  • 没有找到相关文章

最新更新