简体   繁体   English

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

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

while trying to install dependencies for this project, npm install fails with在尝试为此项目安装依赖项时, 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

EDIT编辑

when running npm install --force , I got this other error运行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

EDIT编辑

the second error is thrown while installing node-sass.安装 node-sass 时引发第二个错误。 my node version was not compatible with "node-sass": "^4.14.1".我的节点版本与“node-sass”不兼容:“^4.14.1”。 I have changed node-sass version to be compatible with my node version and this error went away.我已更改 node-sass 版本以与我的 node 版本兼容,并且此错误消失了。 and the build is successful并且构建成功

For first error I tried to install npm by below 2 command in Terminal one after another.对于第一个错误,我尝试在终端中通过以下 2 个命令一个接一个地安装 npm。 It fixes for me:它为我修复:

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

the second error is thrown while installing node-sass.安装 node-sass 时引发第二个错误。 my node version (17.4) was not compatible with "node-sass": "^4.14.1"我的节点版本(17.4)与"node-sass": "^4.14.1"

I have changed node-sass version to be compatible with my node version and this error went away.我已更改 node-sass 版本以与我的 node 版本兼容,并且此错误消失了。 and the build is successful.并且构建成功。

install the dependencies like this:像这样安装依赖项:

npm install <dependencyname> --force

or if you want to install all dependencies at once,或者如果您想一次安装所有依赖项,

npm install --force

Is it still failing?还是失败了吗? for me npm install works without an error using node version 14.16.0对我来说 npm install 使用节点版本 14.16.0 可以正常工作

You need to upgrade your node-sass version to be compatible with the current LTS version of Node.js.你需要升级你的node-sass版本以兼容 Node.js 的当前 LTS 版本。

To do this, change your package.json file to include the following (replacing the old declaration).为此,请更改您的package.json文件以包含以下内容(替换旧声明)。

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

Then, run the following command, and there should be no errors.然后,运行以下命令,应该没有错误。

$ npm install

Ignore the $, it is just to indicate the terminal.忽略$,它只是为了指示终端。

You are getting errors because of the @material-ui/core which is deprecated see: https://www.npmjs.com/package/@material-ui/core the new package for material-ui is https://www.npmjs.com/package/@mui/material .由于不推荐使用的@material-ui/core ,您会遇到错误,请参阅: https ://www.npmjs.com/package/@material-ui/core material-ui 的新包是https://www。 npmjs.com/package/@mui/material

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

  • The minimum supported version of React was increased from v16.8.0 to v17.0.0. React 的最低支持版本从 v16.8.0 增加到 v17.0.0。

You should consider upgrading your react and material ui, they also changed styling tool to emotion, you'll find more info about in the link above.您应该考虑升级您的反应和材料用户界面,他们还将样式工具更改为情感,您将在上面的链接中找到更多信息。 Also, they have pretty good migration guides for cases like yours, check https://mui.com/components/data-grid/migration-v4/#migrating-mui-core-from-v4此外,对于像您这样的情况,他们有很好的迁移指南,请查看https://mui.com/components/data-grid/migration-v4/#migrating-mui-core-from-v4

Temporary alternative can be using force install( npm install --force ) but I really recommend upgrading your dependencies as otherwise there are no warranties that things will work.临时替代方案可以使用强制安装( npm install --force ),但我真的建议升级您的依赖项,否则无法保证一切正常。

Try changing package management to yarn.尝试将包管理更改为纱线。 At present, most packages already support yarn, and its dependency processing is better.目前大部分包已经支持yarn,而且它的依赖处理比较好。

yarn install

Tried all the above solutions but when I Removed all the dependencies and install them one by one, It worked.尝试了上述所有解决方案,但是当我删除所有依赖项并一一安装时,它起作用了。

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

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