Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple versions of same peerDependency required

When I run npm i on my current react project, I get the following warning regarding react peerDependency:

npm WARN [email protected] requires a peer of react@^16.0.0-0 < 16.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.

While in my package.json, I am using latest version of react:

"react": "^16.7.0"

I am new to node and npm. I would like to know what is the good practice for installing npm peerDependencies:

1.) Can the warnings for lower versions be ignored if updated version is already specified in package.json.

2.) As per https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/ and https://github.com/npm/npm/issues/6565

npm provides dependency isolation and peerDepencies needs to be manually installed, so should I install all 3 versions of react but I fear that will break the import statements.

3.) If none of the above two, which version should I use in package.json. P.S. there are many more dependencies in my package.json which might require latest version also.

like image 766
ShailyAggarwal Avatar asked Jan 21 '19 10:01

ShailyAggarwal


2 Answers

A peer dependency means that a package is applicable to used with a particular version of the dependency & wouldn't work as intended if you exceed the specified version.

In your case [email protected] requires a version of React less than 16.4.0, [email protected] requires any version of React 15 and the same for [email protected].

You would need to downgrade from React 16.7.0, but that can break your application if you are using 16.7.0 features, or you could remove the packages and use another one or write the package's logic from start yourself.

Tip: always make sure to read package dependencies on npm website before actually considering to use a package for your project.

like image 74
Danyal Imran Avatar answered Sep 21 '22 12:09

Danyal Imran


Taking Danyal's answer further, you can upgrade formsy-react and remove react-tap-event-plugin:

  1. Update formsy-react to latest version: (1.1.5 at time of writing), the latest version of this package supports react ^16.
  2. react-tap-event-plugin supports react version upto version 16.4. You have a few options here:
    1. Downgrade react: downgrading to 16.4 will remove all the warnings, but will restrict your ability to upgrade in the future
    2. Remove react-tap-event-plugin: According to the documentation https://www.npmjs.com/package/react-tap-event-plugin. This module is actually deprecated thanks to fixes made to later browsers. Check the blog post for info.
    3. Fork react-tap-event-plugin: I wouldn't do this myself, but you could fork the plugin and publish it yourself with the updated react peerDependency.
like image 28
Christopher Slater Avatar answered Sep 19 '22 12:09

Christopher Slater