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

Workspaces complain about missing hoisted peer dependencies #4743

Closed
jquense opened this issue Oct 19, 2017 · 26 comments · Fixed by #5088
Closed

Workspaces complain about missing hoisted peer dependencies #4743

jquense opened this issue Oct 19, 2017 · 26 comments · Fixed by #5088
Assignees

Comments

@jquense
Copy link

jquense commented Oct 19, 2017

What is the current behavior?

peer deps that are hoisted to the repo root are seen as missing by each workspace

If the current behavior is a bug, please provide the steps to reproduce.

Add two workspaces with a Peer dependency and dev dependency on react (or anything in npm). Running yarn results in "[Workspaces package] has unmet peer dependency" warning

You can try it out with: https://github.com/jquense/react-widgets and would see complaints about react, react-dom, moment, and globalize being missing.

What is the expected behavior?

It not to warn

Please mention your node.js, yarn and operating system version.
Yarn 1.2.0, node 8.5 and Mac Sierra

@BYK
Copy link
Member

BYK commented Oct 19, 2017

There was a fix in 1.2.1 which may affect the behavior around this: #4687

Would you like to give it a try?

@jquense
Copy link
Author

jquense commented Oct 19, 2017

Aww I was hoping that was it, but i'm still seeing the warnings on 1.2.1 (just checked)

@likeavirgil
Copy link

likeavirgil commented Oct 25, 2017

Same here with 1.2.1. (Linux 4.10.0-37-generic / Node 8.1.4)

warning "[email protected]" has unmet peer dependency "react@^0.14.0 || ^15.0.0-0 || ^16.0.0-0".

"dependencies": {
  ...
  "react": "15.5.4",
  "react-redux": "5.0.6"
  ...
}

@gandazgul
Copy link
Contributor

Yes, I can confirm this too with yarn 1.2.1 as well as nightly. With workspaces enabled I get peer dep warnings for the workspace aggregator that should be met by dev deps. And I get warning for all hoisted deps in each workspace.

I'll try and look into this issue and see what I can find.

@jpickwell
Copy link

jpickwell commented Nov 3, 2017

I'm also seeing this with the following warnings:

warning " > @rails/[email protected]" has unmet peer dependency "coffeescript@>= 1.12.7 || >= 2.x".
warning "@rails/webpacker > [email protected]" has unmet peer dependency "coffeescript@>= 1.8.x".
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > [email protected]" has unmet peer dependency "css-loader@*".

The coffeescript warnings are legitimate, but caniuse-lite and css-loader are installed and meet the version requirements.

Node 8.2.1, Yarn 1.3.2 (Homebrew), macOS 10.12

@blackxored
Copy link

Same issue here. In addition, it seems like it fails to install one of the modules that it's complaining about.

@jonathancopperstone
Copy link

Experiencing the same issue..

node_modules/
  - react (15.6.2)
  - react-transition-group (2.2.1) 

Where react-transition-group defines react as a peer dependency:

"peerDependencies": {
    "react": ">=15.0.0"
}

but complains with [email protected]" has unmet peer dependency "react@>=15.0.0"

@rally25rs
Copy link
Contributor

Some of these issues seem to be fixed, but some still exist.

For example the case from @likeavirgil no longer throw a warning in 1.3.2.:

"dependencies": {
  "react": "15.5.4",
  "react-redux": "5.0.6"
}

Here is a minimal example of one that still doesn't work in 1.3.2

~/Projects/yarn-test : cat package.json
{
  "name": "yarn-test",
  "version": "0.0.1",
  "description": "yarn-test",
  "author": "",
  "license": "NONE",
  "devDependencies": {
  },
  "dependencies": {
    "@rails/webpacker": "3.0.2",
    "coffeescript": "~1.12.0",
    "caniuse-lite": "^1.0.0"
  }
}

~/Projects/yarn-test : ~/Projects/yarn/bin/yarn
yarn install v1.3.2
warning package.json: License should be a valid SPDX license expression
info No lockfile found.
warning [email protected]: License should be a valid SPDX license expression
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
[4/4] 📃  Building fresh packages...
success Saved lockfile.
✨  Done in 8.85s.

~/Projects/yarn-test : grep version node_modules/caniuse-lite/package.json
  "version": "1.0.30000765",
  "description": "A smaller version of caniuse-db, with only the essentials!",

This seems to be because the code is checking the un-hoisted dependency tree to see if a peerDep is resolved up the trunk, but it fails to check the actual root package.json file's direct dependencies.

@growthcode
Copy link

I was able to fix it after some guessing... I'm new to yarn but fixed 4 warnings including the one here.

[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > [email protected]" has unmet peer dependency "css-loader@*".
warning " > [email protected]" has unmet peer dependency "eslint-plugin-standard@>=3.0.0".
warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
└─ [email protected]
✨  Done in 5.03s.

I'll list my fixes individually so you can see the pattern:

# 1) @rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
bin/yarn add caniuse-lite@^1.0.30000697
# 2) warning " > [email protected]" has unmet peer dependency "css-loader@*".
bin/yarn upgrade css-loader -p
# 3) warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
# 4) warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
yarn upgrade webpack@^2.2.0 || ^3.0.0

Be sure to use the appropriate dependency flags referenced in the warning, more info here:
https://yarnpkg.com/lang/en/docs/managing-dependencies/

After I ran those lines... I got what I spent hours trying to achieve... 0 warnings 😄 :

⇒  yarn install --check-files
yarn install v1.3.2
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
✨  Done in 7.45s.

@rtm
Copy link

rtm commented Nov 27, 2017

@growthcode But the point is you shouldn't need to do that.

@jonathancopperstone
Copy link

I'm currently working on a fix for this, but can't assign it to myself. Is anyone able to grant me access to do so?

@markmcdermid
Copy link

@rally25rs How's this fix going? :)

@rally25rs
Copy link
Contributor

rally25rs commented Dec 11, 2017

@johnnycopperstone ⬆️ (I can lend a hand with this if you haven't made much progress, just let me know.)

@gandazgul
Copy link
Contributor

I'm happy to give some pointers, I tried debugging this and hit a wall. The problem is definitively related to either how yarn builds the tree on a workspace or how the validator works against a workspace tree.

For a simple example of a peerDep not being satisfied by a devDep I see the devDep added to the workspace tree fine, but then when the validator runs it finds that the dep is too far removed from the one with the peer declaration and so it warns (as it should). I don't know enough about how yarn structures the tree and I haven't had time to delve deeper. :(

@rally25rs
Copy link
Contributor

Alright, after much trial and error, I finally came up with a unit test that reproduces this. It calls for a dependency structure like:

package.json
|-dep- b
|  |-peerDep- caniuse-lite
|  |-dep- caniuse-api
|     |-dep- caniuse-lite
|-dep- caniuse-lite

so the peer dep (caniuse-lite) exists at both a shallower and deeper level in the hierarchy relative to where it was requested.

I suspect that when Yarn goes to check for the peerDep, it finds it at b > caniuse-api > caniuse-lite then throws up it's hands and says "nope, that can't be used to satisfy b > caniuse-lite" then stops checking (and never finds the one at the root level that would satisfy the peerDep).

But I have a failing unit test, so that's step 1... 😃

rally25rs added a commit to rally25rs/yarn that referenced this issue Dec 13, 2017
…pkg#4743

Added a failing unit test to reproduce issue yarnpkg#4743. It seems that if a peerDep exists deeper in the
dep tree than where it is included, yarn will output a earning, even if that peerDep is satisfied by
the same library included shallower in the tree, or at the root level.
rally25rs added a commit to rally25rs/yarn that referenced this issue Dec 13, 2017
…multiple levels.

A missing peerDep warning was being issued if the exact same pattern was a deep transitive dep and a
direct dep. This was due to only the first request for a pattern being added to the list of requests
that peerDep was checking. Now all references are tracked. Also fixed a logic error in Warn where a
dep would be reported multiple times.

yarnpkg#4743
@rally25rs
Copy link
Contributor

@johnnycopperstone I know you were working on this, but I went ahead and put together a PR ⬆️ If you could try it out and verify that it works, that would be great!

@Zerim
Copy link

Zerim commented Dec 14, 2017

Adding a reference to this issue: #4503 since it seems related. Generally hoisting seems to cause problems w/ both peer dependencies as well as a host of other tooling that expects scripts, types, etc. to be in the individual workspaces.

@rtm
Copy link

rtm commented Dec 15, 2017 via email

@jonathancopperstone
Copy link

jonathancopperstone commented Dec 19, 2017

Awesome @rally25rs. I didn't get very far, wasn't sure how I could compare the patterns for each dependency with the actual hoisted tree (given it's hoisted as a flat tree with paths as far as I understand). I'll take a look at the PR and test this on our code base today.

arcanis pushed a commit that referenced this issue Jan 15, 2018
…t root level. (#5088)

* test(resolution): Added a (failing) unit test to reproduce issue #4743

Added a failing unit test to reproduce issue #4743. It seems that if a peerDep exists deeper in the
dep tree than where it is included, yarn will output a earning, even if that peerDep is satisfied by
the same library included shallower in the tree, or at the root level.

* fix(resolution): No longer warn for mising peerDep when it exists at multiple levels.

A missing peerDep warning was being issued if the exact same pattern was a deep transitive dep and a
direct dep. This was due to only the first request for a pattern being added to the list of requests
that peerDep was checking. Now all references are tracked. Also fixed a logic error in Warn where a
dep would be reported multiple times.

#4743

* fix(tests): Remove snapshot test of "yarn why" due to different output local vs ci. Now assert with

Remove snapshot test of "yarn why" due to different output local vs ci. Now assert with actual
object value comparison.
@Cedric1994
Copy link

I encoutered this issue using Yarn 1.3.2. The probleme was resolve when I upgrade to the last current version of Yarn (1.5.1)

@nevir
Copy link

nevir commented Nov 15, 2018

I'm encountering this on yarn 1.12.1 :(

@PaulRBerg
Copy link

Same for yarn 1.15.2!

@lkiarest
Copy link

Same for yarn 1.16.0!

@sepehr
Copy link

sepehr commented Sep 5, 2019

Annnd same for 1.17.3.

@KatieMFritz
Copy link

I'm encountering this on 1.22.4

@ttt43ttt
Copy link

Same for yarn 1.22.5!

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

Successfully merging a pull request may close this issue.