繁体   English   中英

npm 安装失败并出现冲突的对等依赖关系:react@16.14.0

[英]npm install fails with Conflicting peer dependency: react@16.14.0

在尝试为此项目安装依赖项时, npm install失败

> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: ecommerce-app@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"latest" from the root project
npm ERR!   peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.11.4
npm ERR!   node_modules/@material-ui/core
npm ERR!     @material-ui/core@"latest" from the root project
npm ERR!     peer @material-ui/core@"^4.0.0" from @material-ui/icons@4.11.2
npm ERR!     node_modules/@material-ui/icons
npm ERR!       @material-ui/icons@"latest" from the root project
npm ERR!     1 more (@material-ui/lab)
npm ERR!   10 more (react-dom, @material-ui/icons, @material-ui/lab, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! redux-form@"^8.3.6" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"^16.4.2" from redux-form@8.3.7
npm ERR!   node_modules/redux-form
npm ERR!     redux-form@"^8.3.6" 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! See /Users/gergo/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gergo/.npm/_logs/2022-03-17T17_37_09_399Z-debug-0.log

编辑

运行npm install --force时,我得到了另一个错误

npm ERR! 2 warnings generated.
npm ERR! In file included from ../src/libsass/src/values.cpp:3:
npm ERR! In file included from ../src/libsass/src/values.hpp:4:
npm ERR! ../src/libsass/src/ast.hpp:1614:25: warning: loop variable 'numerator' of type 'const std::__1::basic_string<char>' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-analysis]
npm ERR!         for (const auto numerator : numerators)
npm ERR!                         ^
npm ERR! ../src/libsass/src/ast.hpp:1614:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
npm ERR!         for (const auto numerator : numerators)
npm ERR!              ^~~~~~~~~~~~~~~~~~~~~~
npm ERR!                         &
npm ERR! ../src/libsass/src/ast.hpp:1616:25: warning: loop variable 'denominator' of type 'const std::__1::basic_string<char>' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-analysis]
npm ERR!         for (const auto denominator : denominators)
npm ERR!                         ^
npm ERR! ../src/libsass/src/ast.hpp:1616:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
npm ERR!         for (const auto denominator : denominators)
npm ERR!              ^~~~~~~~~~~~~~~~~~~~~~~~
npm ERR!                         &
npm ERR! 2 warnings generated.
npm ERR! In file included from ../src/binding.cpp:1:
npm ERR! In file included from ../../nan/nan.h:56:
npm ERR! In file included from /Users/gergo/.node-gyp/17.4.0/include/node/node.h:63:
npm ERR! In file included from /Users/gergo/.node-gyp/17.4.0/include/node/v8.h:25:
npm ERR! In file included from /Users/gergo/.node-gyp/17.4.0/include/node/v8-array-buffer.h:12:
npm ERR! In file included from /Users/gergo/.node-gyp/17.4.0/include/node/v8-local-handle.h:12:
npm ERR! /Users/gergo/.node-gyp/17.4.0/include/node/v8-internal.h:563:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
npm ERR!             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                 ~~~~~^~~~~~~~~~~
npm ERR!                                      remove_cv
npm ERR! /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/type_traits:697:50: note: 'remove_cv' declared here
npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
npm ERR!                                                  ^
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/binding/src/binding.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/gergo/Documents/spring-boot-react-ecommerce-app/client/node_modules/node-gyp/lib/build.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/usr/local/Cellar/node/17.4.0/bin/node" "/Users/gergo/Documents/spring-boot-react-ecommerce-app/client/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /Users/gergo/Documents/spring-boot-react-ecommerce-app/client/node_modules/node-sass
npm ERR! gyp ERR! node -v v17.4.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed with error code: 1

编辑

安装 node-sass 时引发第二个错误。 我的节点版本与“node-sass”不兼容:“^4.14.1”。 我已更改 node-sass 版本以与我的 node 版本兼容,并且此错误消失了。 并且构建成功

对于第一个错误,我尝试在终端中通过以下 2 个命令一个接一个地安装 npm。 它为我修复:

npm install --legacy-peer-deps
npm audit fix --force`

安装 node-sass 时引发第二个错误。 我的节点版本(17.4)与"node-sass": "^4.14.1"

我已更改 node-sass 版本以与我的 node 版本兼容,并且此错误消失了。 并且构建成功。

像这样安装依赖项:

npm install <dependencyname> --force

或者如果您想一次安装所有依赖项,

npm install --force

还是失败了吗? 对我来说 npm install 使用节点版本 14.16.0 可以正常工作

你需要升级你的node-sass版本以兼容 Node.js 的当前 LTS 版本。

为此,请更改您的package.json文件以包含以下内容(替换旧声明)。

{
  "dependencies": {
    "node-sass": "^7.0.1"
  }
}

然后,运行以下命令,应该没有错误。

$ npm install

忽略$,它只是为了指示终端。

由于不推荐使用的@material-ui/core ,您会遇到错误,请参阅: https ://www.npmjs.com/package/@material-ui/core material-ui 的新包是https://www。 npmjs.com/package/@mui/material

正如他们在这里所说的那样https://mui.com/guides/migration-v4/#update-react-amp-typescript-version

  • React 的最低支持版本从 v16.8.0 增加到 v17.0.0。

您应该考虑升级您的反应和材料用户界面,他们还将样式工具更改为情感,您将在上面的链接中找到更多信息。 此外,对于像您这样的情况,他们有很好的迁移指南,请查看https://mui.com/components/data-grid/migration-v4/#migrating-mui-core-from-v4

临时替代方案可以使用强制安装( npm install --force ),但我真的建议升级您的依赖项,否则无法保证一切正常。

尝试将包管理更改为纱线。 目前大部分包已经支持yarn,而且它的依赖处理比较好。

yarn install

尝试了上述所有解决方案,但是当我删除所有依赖项并一一安装时,它起作用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM