我正在尝试运行本教程https://www.ag-grid.com/react-data-grid/getting-started/,当我尝试此npm install --save ag-grid-community ag-grid-react并显示此错误时。
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: ag-grid@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!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.3.0 || ^17.0.0" from ag-grid-react@27.1.0
npm ERR! node_modules/ag-grid-react
npm ERR! ag-grid-react@"*" from the root project
npm ERR!
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\gusta\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\gusta\AppData\Local\npm-cache\_logs\2022-04-08T00_42_18_101Z-debug-0.log
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\gusta\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\gusta\AppData\Local\npm-cache\_logs\2022-04-08T00_45_54_675Z-debug-0.log我很困惑,因为文件上说:
React Version AG Grid Versions
15.x 18 - 21.2.0
16.3+ / 17+ 22+ ```
Looks like my only option is to downgrade my REACT Version.
I am in 18.0.0 . Do you know if I have other options?发布于 2022-04-08 04:32:49
我用这些设置编辑了package.json,以进行降级以响应17.0.2:
"dependencies": {
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
},
Run the
npm install
and
npm install --save ag-grid-community ag-grid-react
Works with no issues.发布于 2022-04-09 17:00:04
我还没有看到ag网格显示与React v18兼容。

用纱线代替npm可以避免这样的错误。
yarn install
然后你就会收到警告而不是失败的构建
warning " > ag-grid-react@27.1.0" has incorrect peer dependency "react@^16.3.0 || ^17.0.0".
https://stackoverflow.com/questions/71790492
复制相似问题