Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm issues with UNMET PEER DEPENDENCY, related to react-native

I think I'm confused as to how npm manages dependencies. I see this:

npm list react-native
[email protected] /Users/me/workspace/project
└── UNMET PEER DEPENDENCY [email protected]

npm ERR! peer dep missing: react-native@^0.13.2, required by [email protected]
npm ERR! code 1

So I try... but I get:

   npm install [email protected]

    ....

    [email protected] /Users/me/workspace/project
└─┬ UNMET PEER DEPENDENCY [email protected]
  └── [email protected]  (git+https://github.com/facebook/react.git#b4e74e38e43ac53af8acd62c78c9213be0194245)

npm WARN EPEERINVALID [email protected] requires a peer of react-native@^0.13.2 but none was installed.
npm ERR! code 1

My package.json:

{
  "name": "project",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start"
  },
  "dependencies": {
    "apsl-react-native-button": "^2.1.0",
    "base-64": "^0.1.0",
    "es6-react-mixins": "^0.2.1",
    "fifo": "^2.3.0",
    "money-math": "^2.2.0",
    "react-native": "^0.15.0",
    "react-native-dropdown-android": "0.0.4",
    "react-native-lightbox": "^0.5.0",
    "react-native-mail": "^0.2.4",
    "react-native-router-flux": "^0.3.4",
    "react-native-simpledialog-android": "^1.0.2",
    "react-native-swiper": "^1.3.0",
    "superagent": "^1.4.0",
    "tcomb-form-native": "^0.3.0",
    "utf8": "^2.1.1",
    "react-native-facebook-login": "^1.0.0"
  }
}
like image 896
Newy Avatar asked Dec 04 '15 00:12

Newy


1 Answers

I know it's an old question, but a response can still be useful for others seeing this in the future.

Explanation of the issue

In your package.json, you are installing the dependency [email protected] which is as well expecting as a peerDependency the module: react-native@^0.13.2. Since that project is public, it can be verified in their package.json file:

  "peerDependencies": {
    "react-native": "^0.13.2"
  }

The first part of this statement, is the module name, and the second part, the supported version range.

This means that the root module should provide such dependency and in such version range, in order for the installation to succeed with no errors. In this case, it's stating react-native dependency, and in the ^0.13.2 version range.

Now, in your package.json, you are listing the dependency:

    "react-native": "^0.15.0",

So why is it not working? The ^ (caret) in version range should include all patch and minor versions in the same major, right? (ie. in "^X.Y.Z" range, all X.*.* should work, right?). Well, turns out this isn't true for pre-1.x ranges. For 0.x ranges, the ^ caret only covers patch versions inside the range (source: NPM docs).

Therefore, per this rule, "^0.15.0" is not in the range of "^0.13.2", so this is why you get the UNMET PEER DEPENDENCY error.

Possible solutions

You have a few options here.

Provide the expected peer dependency

The most straightforward one, is providing the expected peer dependency in a version that is in the expected version range.

So you could use the same version range, in this case: "^0.13.2". Or specify an exact version as well, for example: "0.13.2".

Tip: you can check all versions that match the requested range for a given package, using this utility https://semver.npmjs.com/.

For this case, the only version that exists and matches the range is "0.13.2", but there could've been more (ie. "0.13.3" could've been fine as well, if it existed. But "0.14.0" or "0.12.0" won't work, as explained above)

Update your module dependency

In many cases the original module gets upgraded, and changes may include supporting different or more broad peerDependencies packages/versions.

As of today, I can see in the package.json on the project master branch, that the current module version is 1.1.1 and the peerDependencies have been removed, so upgrading your "react-native-dialogs" dependency version ^0.0.5 -> ^1.1.1 will do the job for this scenario.

But, what if this didn't happen, or if you didn't want to upgrade to the latest version?Let's explore more options.

Change the module itself that you want to depend on

In case that providing the dependency version requested as a peerDependency by a module you use conflicts with your requirements, and upgrading this dependency to a newer version that removes this constraint doesn't work for you.

The allowed range "^0.13.2" might be quite limited, ie. it won't support version 0.14.0 and onwards. The reasoning behind this, could be based on compatibilty issues, or maybe just a lack of awareness in allowing/supporting for more versions. There could happen to exist other versions that can work fine, but the original developer did not take the extra steps to include them.

So you just want to continue using this exact module as is, but allow a newer react-native version.

Imagining the original scenario, that 0.0.5 was the current latest version in the master branch, it could make sense raising this as an issue to the original module repo, and/or submit them a PR proposing a broader supported range. For example:

  "peerDependencies": {
    "react-native": "< 1.0.0"
  }

The range "< 1.0.0" would now allow the "^0.15.2" version range.

What if you didn't want to allow all the 0.x versions? Then you could use a more narrow range, such as: "> 0.4.0 < 1.0.0". Take a look at NPM semver docs for syntax, a lot more possibilities are allowed too.

Don't use that module at all / Build your own

It can happen that the original module can be abandoned, have bugs, or just not work for your all of your requirements. In this case, you can look for a some alternative available in the community, or even build one yourself.

Since this module is public you can even fork the project and upload a new package version yourself with the changes you want (you'll have to use a different package name of course).

like image 61
tmilar Avatar answered Sep 18 '22 08:09

tmilar