npm安装失败,对等依赖项冲突:16.14.0时的React

evrscar2  于 2023-03-08  发布在  React
关注(0)|答案(8)|浏览(491)

尝试安装this项目的依赖项时,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
    • 编辑**

第二个错误是抛出while安装node-sass.我的节点版本是不兼容的与"node-sass":"^4.14.1"。我已将node-sass版本更改为与我的节点版本兼容,此错误已消失,生成成功

zlhcx6iw

zlhcx6iw1#

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

npm install --legacy-peer-deps
npm audit fix --force
  • B:安装后不要忘记重新启动终端
n3ipq98p

n3ipq98p2#

由于@material-ui/core已弃用,您将收到错误,请参阅:https://www.npmjs.com/package/@material-ui/core材质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。

你应该考虑升级一下你的react和material用户界面,他们也把样式工具改成了emotion,你可以在上面的链接中找到更多的信息。另外,他们也有很好的迁移指南来帮助你,请访问https://mui.com/components/data-grid/migration-v4/#migrating-mui-core-from-v4
临时替代方案可以使用强制安装(npm install --force),但我真的建议升级您的依赖项,否则没有任何保证,事情会工作。

vu8f3i0k

vu8f3i0k3#

按如下方式安装依赖项:

npm install <dependencyname> --force

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

npm install --force
chhkpiq4

chhkpiq44#

安装node-sass时抛出第二个错误。我的节点版本(17.4)与"node-sass": "^4.14.1"不兼容
我已经更改了node-sass版本,使其与我的节点版本兼容,这个错误消失了,并且构建成功。

iszxjhcz

iszxjhcz5#

尝试将 Package 管理改为Yarn,目前大部分 Package 已经支持Yarn,其依赖处理更好。

yarn install
vsnjm48y

vsnjm48y6#

它仍然失败吗?对于我,使用节点版本14.16.0时,npm安装工作正常,没有错误

qxsslcnc

qxsslcnc7#

您需要升级您的node-sass版本,以便与当前LTS版本的Node.js兼容。
为此,请更改您的package.json文件以包含以下内容(替换旧声明)。

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

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

$ npm install

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

z9smfwbn

z9smfwbn8#

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

相关问题