user606006
user606006

Reputation: 459

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

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 [email protected], but also tries to install [email protected], which requires [email protected]. I get the following error:

npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
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 [email protected]
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/[email protected]
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!

Then I tried to resolve this by installing [email protected] 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/[email protected] depends on react-native-windows@^0.6.20, which depends on [email protected], giving me this error instead:

npm ERR! Found: [email protected]
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 [email protected]
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/[email protected]
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?

Upvotes: 3

Views: 5120

Answers (3)

Talwinder Singh
Talwinder Singh

Reputation: 1

Try doing npm install --legacy-peer-deps

Upvotes: 0

Apurva Aggarwal
Apurva Aggarwal

Reputation: 297

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

Upvotes: 0

user606006
user606006

Reputation: 459

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

Upvotes: 10

Related Questions