安装flux遇到react需要降级的情况

问题

运行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: [email protected]
npm ERR! Found: [email protected]
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 [email protected]
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         
[email protected] /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

2.安装react,版本为16

$ npm install [email protected]
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@"^18.0.0" from @testing-library/[email protected]
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/[email protected]
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: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@"^18.0.0" from @testing-library/[email protected]
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 [email protected]
npm WARN node_modules/react-dom
npm WARN   peer react-dom@"^18.0.0" from @testing-library/[email protected]
npm WARN   node_modules/@testing-library/react
npm WARN   1 more (the root project)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@"^18.0.0" from @testing-library/[email protected]
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 [email protected]
npm WARN node_modules/react-dom
npm WARN   peer react-dom@"^18.0.0" from @testing-library/[email protected]
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          
[email protected] /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped invalid: "^18.0.0" from node_modules/@testing-library/react
├─┬ [email protected]
│ └── [email protected] deduped invalid: "^18.0.0" from node_modules/@testing-library/react, "^18.2.0" from node_modules/react-dom
└── [email protected] 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: [email protected] /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          
[email protected] /Users/xxx/WebstormProjects/my_first_react_project
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

你可能感兴趣的:(react.js,前端,前端框架)