How do you properly resolve NPM dependencies in projects that require conflicting versions?

Viewed 3480

I'm trying to build the playground app for react-native-navigation using instructions here. A simple npm install fails because the peer dependencies have react: "*" and react-native: "*", so today (Jan 2021) NPM tries to install react@17.0.1, but also tries to install react-native@0.63.4, which requires react@16.13.1. I get the following error:

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!

Then I tried to resolve this by installing react@16.13.1 in my root project, hoping that NPM would detect and use that version as a peer dependency, but then it turns out @react-native-community/datetimepicker@2.6.2 depends on react-native-windows@^0.6.20, which depends on react@16.11.0, giving me this error instead:

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!

How do I get to the bottom of this? I was expecting everything to just work with npm install. What is the proper way to install a project, or is it common to have to constantly debug dependency conflicts prior to starting a project?

3 Answers

As it turns out, I was using node 15.0.x which is apparently too new. Downgrading to 14.15.1 worked.

I too was using node 15.0.x. Downgrading to 14.x.x worked.

Try doing npm install --legacy-peer-deps

Related