在需要版本冲突的项目中,如何正确解决 NPM 依赖?
How do you properly resolve NPM dependencies in projects that require conflicting versions?
我正在尝试使用说明 here 为 react-native-navigation
构建 playground 应用程序。一个简单的 npm install
失败,因为对等依赖项有 react: "*"
和 react-native: "*"
,所以今天(2021 年 1 月)NPM 尝试安装 react@17.0.1
,但也尝试安装 react-native@0.63.4
,这需要 react@16.13.1
。我收到以下错误:
npm ERR! While resolving: react-native-navigation@7.7.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR! peer react@"*" from the root project
...
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native@0.63.4
npm ERR! node_modules/react-native
npm ERR! peer react-native@"*" from the root project
npm ERR! peer react-native@">=0.59" from @react-native-community/datetimepicker@2.6.2
npm ERR! node_modules/@react-native-community/datetimepicker
npm ERR!
然后我尝试通过在我的根项目中安装 react@16.13.1
来解决这个问题,希望 NPM 能够检测到该版本并将其用作对等依赖项,但后来发现 @react-native-community/datetimepicker@2.6.2
依赖于 react-native-windows@^0.6.20
,这取决于 react@16.11.0
,而是给我这个错误:
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR! dev react@"16.13.1" from the root project
...
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.11.0" from react-native-windows@0.62.20
npm ERR! node_modules/@react-native-community/datetimepicker/node_modules/react-native-windows
npm ERR! optional react-native-windows@"^0.62.0-0" from @react-native-community/datetimepicker@2.6.2
npm ERR! node_modules/@react-native-community/datetimepicker
npm ERR! dev @react-native-community/datetimepicker@"^2.5.0" from the root project
npm ERR! 1 more (react-native-ui-lib)
npm ERR!
我如何弄清楚这个问题?我期待一切都能与 npm install
一起工作。安装项目的正确方法是什么,或者在启动项目之前必须不断调试依赖冲突?
事实证明,我使用的是节点 15.0.x,这显然太新了。降级到 14.15.1 有效。
我也在使用节点 15。0.x。降级到 14.x.x 有效。
尝试执行 npm install --legacy-peer-deps
我正在尝试使用说明 here 为 react-native-navigation
构建 playground 应用程序。一个简单的 npm install
失败,因为对等依赖项有 react: "*"
和 react-native: "*"
,所以今天(2021 年 1 月)NPM 尝试安装 react@17.0.1
,但也尝试安装 react-native@0.63.4
,这需要 react@16.13.1
。我收到以下错误:
npm ERR! While resolving: react-native-navigation@7.7.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR! peer react@"*" from the root project
...
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native@0.63.4
npm ERR! node_modules/react-native
npm ERR! peer react-native@"*" from the root project
npm ERR! peer react-native@">=0.59" from @react-native-community/datetimepicker@2.6.2
npm ERR! node_modules/@react-native-community/datetimepicker
npm ERR!
然后我尝试通过在我的根项目中安装 react@16.13.1
来解决这个问题,希望 NPM 能够检测到该版本并将其用作对等依赖项,但后来发现 @react-native-community/datetimepicker@2.6.2
依赖于 react-native-windows@^0.6.20
,这取决于 react@16.11.0
,而是给我这个错误:
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR! dev react@"16.13.1" from the root project
...
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.11.0" from react-native-windows@0.62.20
npm ERR! node_modules/@react-native-community/datetimepicker/node_modules/react-native-windows
npm ERR! optional react-native-windows@"^0.62.0-0" from @react-native-community/datetimepicker@2.6.2
npm ERR! node_modules/@react-native-community/datetimepicker
npm ERR! dev @react-native-community/datetimepicker@"^2.5.0" from the root project
npm ERR! 1 more (react-native-ui-lib)
npm ERR!
我如何弄清楚这个问题?我期待一切都能与 npm install
一起工作。安装项目的正确方法是什么,或者在启动项目之前必须不断调试依赖冲突?
事实证明,我使用的是节点 15.0.x,这显然太新了。降级到 14.15.1 有效。
我也在使用节点 15。0.x。降级到 14.x.x 有效。
尝试执行 npm install --legacy-peer-deps