我正在尝试安装react cogo toast,但是在我使用命令 npm install --save cogo-toast 之后我在控制台中可以看到的是:

问题描述 投票:0回答:1

npm 错误!代码 ERESOLVE npm 错误! ERESOLVE 无法解析依赖关系树 npm 错误! npm 错误!解决时:[电子邮件受保护] npm 错误!找到:[电子邮件受保护] npm 错误!节点模块/反应 npm 错误!来自根项目的react@“^18.2.0” npm 错误! npm 错误!无法解决依赖关系: npm 错误!来自 [电子邮件受保护] 的同伴 React@“^16.8.0” npm 错误!节点模块/cogo-toast npm 错误!来自根项目的 cogo-toast@"*" npm 错误! npm 错误!修复上游依赖冲突,或重试 npm 错误!此命令与 --force 或 --legacy-peer-deps npm 错误!接受不正确的(并且可能损坏的)依赖关系解析。 npm 错误! npm 错误!请参阅 C:\Users\JHONY\AppData\Local pm-cacheresolve-report.txt 获取完整报告。

npm 错误!此运行的完整日志可以在以下位置找到: npm 错误!

C:\Users\JHONY\AppData\Local pm-cache_logs�2-12-22T10_57_19_718Z-debug-0.log

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 4ms
6 timing config:load:builtin Completed in 4ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:F:\Course\Ostad\Practice\React\react-bootstrap\.npmrc Completed in 0ms
10 timing config:load:project Completed in 4ms
11 timing config:load:file:C:\Users\JHONY\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\JHONY\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 14ms
19 timing npm:load:configload Completed in 14ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 0ms
22 verbose title npm install cogo-toast
23 verbose argv "install" "--save" "cogo-toast"
24 timing npm:load:setTitle Completed in 2ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 3ms
27 verbose logfile logs-max:10 dir:C:\Users\JHONY\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\JHONY\AppData\Local\npm-cache\_logs\2022-12-22T10_52_18_092Z-debug-0.log
29 timing npm:load:logFile Completed in 5ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 25ms
33 timing arborist:ctor Completed in 0ms
34 silly logfile start cleaning logs, removing 2 files
35 silly logfile done cleaning log files
36 timing idealTree:init Completed in 706ms
37 timing idealTree:userRequests Completed in 4ms
38 silly idealTree buildDeps
39 silly fetch manifest cogo-toast@*
40 timing arborist:ctor Completed in 0ms
41 http fetch GET 200 https://registry.npmjs.org/cogo-toast 625ms (cache hit)
42 silly fetch manifest prop-types@^15.6.2
43 http fetch GET 200 https://registry.npmjs.org/prop-types 6ms (cache hit)
44 silly fetch manifest react@^18.2.0
45 http fetch GET 200 https://registry.npmjs.org/react 7ms (cache hit)
46 silly fetch manifest react@^16.8.0
47 timing idealTree Completed in 1370ms
48 timing command:install Completed in 1381ms
49 verbose stack Error: unable to resolve dependency tree
49 verbose stack     at Arborist.[failPeerConflict] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1428:25)
49 verbose stack     at Arborist.[loadPeerSet] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1394:34)
49 verbose stack     at async Arborist.[buildDepStep] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:976:11)
49 verbose stack     at async Arborist.buildIdealTree (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:218:7)
49 verbose stack     at async Promise.all (index 1)
49 verbose stack     at async Arborist.reify (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:153:5)
49 verbose stack     at async Install.exec (C:\Program Files\nodejs\node_modules\npm\lib\commands\install.js:156:5)
49 verbose stack     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli.js:78:5)
50 verbose cwd F:\Course\Ostad\Practice\React\react-bootstrap
51 verbose Windows_NT 10.0.22621
52 verbose node v16.16.0
53 verbose npm  v8.11.0
54 error code ERESOLVE
55 error ERESOLVE unable to resolve dependency tree
56 error
57 error While resolving: [1mreact-bootstrap[22m@[1m0.1.0[22m
57 error Found: [1mreact[22m@[1m18.2.0[22m[2m[22m
57 error [2mnode_modules/react[22m
57 error   [1mreact[22m@"[1m^18.2.0[22m" from the root project
57 error
57 error Could not resolve dependency:
57 error [35mpeer[39m [1mreact[22m@"[1m^16.8.0[22m" from [1mcogo-toast[22m@[1m4.2.3[22m[2m[22m
57 error [2mnode_modules/cogo-toast[22m
57 error   [1mcogo-toast[22m@"[1m*[22m" from the root project
57 error
57 error Fix the upstream dependency conflict, or retry
57 error this command with --force, or --legacy-peer-deps
57 error to accept an incorrect (and potentially broken) dependency resolution.
57 error
57 error See C:\Users\JHONY\AppData\Local\npm-cache\eresolve-report.txt for a full report.
58 verbose exit 1
59 timing npm Completed in 1501ms
60 verbose unfinished npm timer reify 1671706338204
61 verbose unfinished npm timer reify:loadTrees 1671706338212
62 verbose unfinished npm timer idealTree:buildDeps 1671706338923
63 verbose unfinished npm timer idealTree:#root 1671706338923
64 verbose code 1
65 error A complete log of this run can be found in:
65 error     C:\Users\JHONY\AppData\Local\npm-cache\_logs\2022-12-22T10_52_18_092Z-debug-0.log

如何解决这个问题?

reactjs toast
1个回答
0
投票

您似乎遇到了依赖冲突,因为

cogo-toast
库需要与您正在使用的 React 18.2.0 不兼容的 React 版本。我在一个名为
cogo-toast-react-17-fix
的包中开发了针对此问题的修复程序。这个包提供了一个与 React 17 和更新版本(包括 React 18)兼容的
cogo-toast
版本。以下是如何使用它:

  1. 首先,删除现有的
    cogo-toast
    软件包(如果已安装):
npm uninstall cogo-toast
  1. 然后,安装
    cogo-toast-react-17-fix
    软件包:
npm install cogo-toast-react-17-fix
  1. 现在,您可以在项目中使用
    cogo-toast-react-17-fix
    ,就像使用
    cogo-toast
    一样。这是显示成功 toast 的示例:
import toast from 'cogo-toast-react-17-fix';

toast.success('This is a success message!', {
  position: 'bottom-center',
  heading: 'Success!',
  hideAfter: 5 // hides the toast after 5 seconds
});

此包应该可以解决您在 React 18.2.0 中遇到的依赖冲突,并允许您继续在项目中使用

cogo-toast
功能。

© www.soinside.com 2019 - 2024. All rights reserved.