安装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: 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值