问题
运行npm install --save flux
,提示react
的版本不对,当前是18,但flux只支持react@"^15.0.2 || ^16.0.0 || ^17.0.0"
$ npm install --save flux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my_first_react_project@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@"^15.0.2 || ^16.0.0 || ^17.0.0" from flux@4.0.4
npm ERR! node_modules/flux
npm ERR! flux@"*" 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:
npm ERR! /Users/xxx/.npm/_logs/2023-07-28T07_07_01_626Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: /Users/xxx/.npm/_logs/2023-07-28T07_07_01_626Z-debug-0.log
(
解决
1.查看react
版本
$ npm list react
my_first_react_project@0.1.0 /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/react@13.4.0
│ └── react@18.2.0 deduped
├─┬ react-dom@18.2.0
│ └── react@18.2.0 deduped
└── react@18.2.0
2.安装react
,版本为16
$ npm install react@16.8.0
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: my_first_react_project@0.1.0
npm WARN Found: react@18.2.0
npm WARN node_modules/react
npm WARN peer react@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN @testing-library/react@"^13.4.0" from the root project
npm WARN 2 more (react-dom, the root project)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN @testing-library/react@"^13.4.0" from the root project
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: my_first_react_project@0.1.0
npm WARN Found: react@18.2.0
npm WARN node_modules/react
npm WARN peer react@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN @testing-library/react@"^13.4.0" from the root project
npm WARN 2 more (react-dom, the root project)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^18.2.0" from react-dom@18.2.0
npm WARN node_modules/react-dom
npm WARN peer react-dom@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN 1 more (the root project)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: my_first_react_project@0.1.0
npm WARN Found: react@18.2.0
npm WARN node_modules/react
npm WARN peer react@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN @testing-library/react@"^13.4.0" from the root project
npm WARN 2 more (react-dom, the root project)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^18.2.0" from react-dom@18.2.0
npm WARN node_modules/react-dom
npm WARN peer react-dom@"^18.0.0" from @testing-library/react@13.4.0
npm WARN node_modules/@testing-library/react
npm WARN 1 more (the root project)
added 1 package, changed 1 package, and audited 1500 packages in 3s
239 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
3.再次查看react
版本,结果出现错误,提示有不一致的地方
$ npm list react
my_first_react_project@0.1.0 /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/react@13.4.0
│ └── react@16.8.0 deduped invalid: "^18.0.0" from node_modules/@testing-library/react
├─┬ react-dom@18.2.0
│ └── react@16.8.0 deduped invalid: "^18.0.0" from node_modules/@testing-library/react, "^18.2.0" from node_modules/react-dom
└── react@16.8.0 invalid: "^18.0.0" from node_modules/@testing-library/react, "^18.2.0" from node_modules/react-dom
npm ERR! code ELSPROBLEMS
npm ERR! invalid: react@16.8.0 /Users/xxx/WebstormProjects/my_first_react_project/node_modules/react
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxx/.npm/_logs/2023-07-28T07_15_42_049Z-debug-0.log
4.重新安装react-dom
,版本为16
$ npm install react-dom@16
added 4 packages, removed 5 packages, changed 3 packages, and audited 1499 packages in 4s
239 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
5.再次查看react
版本,结果正常
$ npm list react
my_first_react_project@0.1.0 /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/react@13.4.0
│ └── react@16.14.0 deduped
├─┬ react-dom@16.14.0
│ └── react@16.14.0 deduped
└── react@16.14.0