Skip to content

Using yarn and hoisting together causes yarn.lock to be ignored #852

Closed

Description

@ef4

If you try to use --npm-client=yarn and --hoist simultaneously, all your package's yarn.lock files will be ignored because lerna uses npm instead of yarn for everything except the top-level hoisted dependencies.

Expected Behavior

When using yarn as the npm client, all installed dependencies should satisfy any yarn.lock files that are present.

Current Behavior

lerna invokes npm --global-style instead of yarn in each of the packages, causing the yarn.lock to be ignored.

Possible Solution

We could forbid the combination of hoisting and yarn, or at least warn that it will give surprising results.

A more complete solution would mangle the contents of yarn.lock in a way analogous to what lerna already does for package.json in order to preserve the intended semantics.

Steps to Reproduce (for bugs)

  1. In any lerna project, run lerna bootstrap --hoist --npm-client=yarn
  2. Observe the resulting processes via ps or pstree and see that lerna is running npm instead of yarn.

Activity

  1. thomasfr commented on Jun 1, 2017

    @thomasfr

    I can confirm this. We are using --hoist and --npm-client=yarn together and when doing lerna bootstrap i can see npm install --global-style

  2. evocateur commented on Jun 6, 2017

    @evocateur
    Member

    mangle the contents of yarn.lock

    😨 uhhh, pardon my shock, but that's asking us to reverse-engineer yarn. Definitely not happening. Warn about --npm-client=yarn + --hoist, sure, that's possible.

    npm install --global-style is important to avoid improper transitive dependency resolution for non-hoisted dependencies. If you want to use yarn everywhere, yarn will have to be extended to support that, which is obviously out of scope for lerna itself.

  3. MoOx commented on Jun 10, 2017

    @MoOx

    Yarn will have a built in feature, called "workspaces" to offer a lerna like solution. More at yarnpkg/yarn#3294

  4. thomasfr commented on Jun 11, 2017

    @thomasfr

    @evocateur @MoOx Do you know what this would mean to lerna? Would Lerna then be obsolete? Or would Lerna just use this workspaces feature?

  5. evocateur commented on Jun 11, 2017

    @evocateur
    Member
  6. added a commit that references this issue on Jun 19, 2017
  7. ebramanti commented on Jun 20, 2017

    @ebramanti

    So if using yarn as the npmClient, hoist will use npm instead of yarn always?

  8. evocateur commented on Jun 20, 2017

    @evocateur
    Member

    If --hoist needs to do a leaf install (i.e., there are "unhoisted", possibly conflicting deps in the tree), then it will use npm because yarn does not support --global-install, which avoids leaking transitive dependencies incorrectly.

  9. edmorley commented on Sep 29, 2017

    @edmorley

    I spent a while trying to debug/create a reduced STR for why using --hoist plus yarn caused a package-lock.json to be created in one of the sub-package directories. Reading here it seems that this is because lerna has to fall back to npm for parts of the operation, and as such yarn + --hoist is not recommended.

    If that's the case, a warning message during usage would save a lot of confusion :-) (And perhaps a note saying to use the workspaces support instead?)

  10. evocateur commented on Nov 20, 2017

    @evocateur
    Member

    #1063 fixed this by making it error when --npm-client yarn and --hoist are used together, released in v2.5.0.

  11. lock commented on Dec 27, 2018

    @lock

    This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  12. locked as resolved and limited conversation to collaborators on Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions