Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmet peer dependency warning when the peer dependency is installed at the same time #2132

Closed
fson opened this issue Dec 3, 2016 · 13 comments

Comments

@fson
Copy link

fson commented Dec 3, 2016

Bug

What is the current behavior?

Installing a dependency and its peer dependency at the same time generates a warning "Unmet peer dependency" even though the peer dependency is installed.

Steps to reproduce:

> mkdir test
> cd test
> yarn init -y
> yarn add react react-dom
yarn add v0.17.10
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning Unmet peer dependency "react@^15.4.1".

On the other hand, first running yarn add react and then yarn add react-dom doesn't create any warnings.

What is the expected behavior?

No warnings about peer dependencies should be printed when other packages specified in the add command will satisfy the peer dependencies.

Please mention your node.js, yarn and operating system version.

Node.js v6.9.1
Yarn 0.17.10
macOS 10.12.1

@andreiglingeanu
Copy link

Can confirm this.

I've got while doing yarn add babel-plugin-transform-vue-jsx.

warning Unmet peer dependency "babel-helper-vue-jsx-merge-props@^2.0.0".
warning Unmet peer dependency "babel-plugin-syntax-jsx@^6.8.0".

@connesc
Copy link
Contributor

connesc commented Jan 12, 2017

Same here with yarn add request request-promise-native:

warning Unmet peer dependency "request@^2.34".
warning Unmet peer dependency "request@^2.34".

@idibidiart
Copy link

Same issue.

@idibidiart
Copy link

low priority?

@gaearon
Copy link
Contributor

gaearon commented Feb 11, 2017

Would you like to send a PR to fix it?

@idibidiart
Copy link

@gaearon

do you have any idea what part(s) of the Yarn code the PR would have to touch (potentially)? :)

@gaearon
Copy link
Contributor

gaearon commented Feb 18, 2017

Not really :-). I'd just recommend searching for the error message string and then seeing where it's used.

@andreiglingeanu
Copy link

@gaearon Yeah, right here :)

@kamilogorek
Copy link
Contributor

kamilogorek commented Feb 27, 2017

After some debugging, and using yarn add request request-promise-native as a test case, I found that the main issue is this code:

const dep = this.resolver.getResolvedPattern(pattern);

this.resolver.getResolvedPattern(pattern)

is expecting a pattern in a very specific form eg. request@^2.79.0, which is available in this.resolver.patterns map.

However, what's passed is just request string, therefore it will always return undefined.

I was able to fix it successfully using this code:

    for (const name in peerDeps) {
      const range = peerDeps[name];
      const packageInfo = this.resolver.getAllInfoForPackageName(name)
      const hasAnyPackageVersion = packageInfo.length !== 0
      const foundDep = packageInfo.find((entry) => this._satisfiesPeerDependency(range, entry.version))

      if (foundDep) {
        ref.addDependencies([`${foundDep.name}@^${foundDep.version}`])
      } else {
        const depError = hasAnyPackageVersion ? 'incorrectPeer' : 'unmetPeer';
        const pkgHuman = `${pkg.name}@${pkg.version}`,
              depHuman = `${name}@${range}`;
        this.reporter.warn(this.reporter.lang(depError, pkgHuman, depHuman));
      }
    }

But this line ref.addDependencies([${foundDep.name}@^${foundDep.version}]) is assuming a carret range, which is not right. I'm not able to pull a specific pattern that I can store using ref.addDependencies.

Any pointers how I should approach it?

@ambethia
Copy link

I believe this issue can be closed. Updating to yarn 0.22 (from 0.21.3) resolved this for me.

@SimenB
Copy link
Contributor

SimenB commented Apr 10, 2017

Agreed, fixed in #2801 🎉

@andreiglingeanu
Copy link

Works fine!

@fson
Copy link
Author

fson commented Apr 10, 2017

Indeed, this works correctly in 0.22.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants