Skip to content

lerna bootstrap failing as a postinstall step with yarn workspaces #1308

Closed
@ForbesLindesay

Description

@ForbesLindesay

Expected Behavior

I want to put "lerna bootstrap" in the "postinstall" script so that people who don't realise that lerna has a boostrap step can just run "yarn" and have everything set up for them.

Current Behavior

It hangs for ever on "lerna bootstrap". If I remove the "postinstall" step and run yarn and lerna bootstrap as separate steps, they each complete in a couple of seconds.

Steps to Reproduce (for bugs)

  1. clone https://github.com/pugjs/pug
  2. open package.json
  3. rename the "bootstrap" step to "postinstall"
  4. run yarn
lerna.json

{
  "lerna": "2.9.0",
  "packages": ["packages/*"],
  "npmClient": "yarn",
  "useWorkspaces": true,
  "version": "independent",
  "registry": "https://registry.npmjs.org/"
}

lerna-debug.log

after a few minutes, it was still running and no log had appeared

package.json

{
  "name": "pug-monorepo",
  "private": true,
  "devDependencies": {
    "coveralls": "^2.11.2",
    "jest": "^18.1.0",
    "lerna": "2.9.0",
    "prettier": "^1.3.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/pugjs/pug.git"
  },
  "scripts": {
    "postinstall": "lerna bootstrap",
    "clean": "lerna clean",
    "release": "lerna publish",
    "pretest": "lerna run pretest",
    "test": "jest",
    "coverage": "jest --coverage",
    "coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
    "watch": "jest --watch"
  },
  "jest": {
    "testEnvironment": "node",
    "snapshotSerializers": [
      "./scripts/filename-serializer.js",
      "./scripts/prettier-javascript-serializer.js"
    ]
  },
  "license": "MIT",
  "workspaces": ["packages/*"]
}

Context

People have to know to run yarn bootstrap after installing.

Your Environment

Executable Version
lerna --version 2.9.0
npm --version 5.6.0
yarn --version 1.3.2
node --version v8.9.4
OS Version
macOS High Sierra 10.13.3

Activity

evocateur

evocateur commented on Mar 6, 2018

@evocateur
Member

lerna bootstrap when you're using Yarn workspaces is literally redundant? All lerna bootstrap --npm-client yarn --use-workspaces (CLI equivalent of your lerna.json config) does is call yarn install in the root. With a postinstall that calls lerna bootstrap again, it's just going further down the infinitely recursive rabbit-hole.

Should we throw an error when people try lerna bootstrap --npm-client yarn --use-workspaces, telling them "just use yarn"?

ForbesLindesay

ForbesLindesay commented on Mar 7, 2018

@ForbesLindesay
Author

Yes, that would be a big improvement. It would also be good to add something to the readme along with the bits on setting up yarn workspaces.

davidhouweling

davidhouweling commented on Mar 12, 2018

@davidhouweling

I just tried it but it doesn't look like it resolves sibling packages. This is evident when you do testing for example.

davidhouweling

davidhouweling commented on Mar 13, 2018

@davidhouweling

So after a bit more experimenting and searching other issues, I had to run the prepublish and prepare scripts of each package...

evocateur

evocateur commented on Mar 13, 2018

@evocateur
Member

That sounds like a yarn workspaces problem, then. Lerna is literally doing nothing special when you run bootstrap with workspaces enabled.

davidhouweling

davidhouweling commented on Mar 13, 2018

@davidhouweling

@evocateur I think there is a difference of opinion there. From the yarn blog itself:

Jest relies on Yarn to bootstrap the project, and on Lerna for running the publish command(s).

Based on this, I believe https://github.com/lerna/lerna/blob/master/commands/bootstrap/index.js#L90 should also execute https://github.com/lerna/lerna/blob/master/commands/bootstrap/index.js#L95-L104

evocateur

evocateur commented on Mar 13, 2018

@evocateur
Member

I just tried it but it doesn't look like it resolves sibling packages. This is evident when you do testing for example.

Literally no context, example, etc etc etc. What "it" were you referring to?

I think there is a difference of opinion there.

#899 (written by one of the yarn maintainers) disagrees with you.

Bootstrap has nothing at all to do with publishing. Lifecycles like prepublish, prepare, etc are all run by the npm client doing the publishing, not lerna (we only run a synthetic version lifecycle). If you're using yarn to bootstrap and publish, that's on yarn to fix their shit. npm does perfectly fine with lerna publish's responsibilities.

If lerna is calling yarn incorrectly, that's something we can fix. So far I have seen no evidence of this, however.

davidhouweling

davidhouweling commented on Mar 14, 2018

@davidhouweling

Thanks for the response and I am sorry I was a bit vague with my first comment. "it' being using workspaces as directed by the blog post and lerna.

After a bit of digging on the yarn issues side, it at least is an issue on their end that is tracked as well: yarnpkg/yarn#3911

For now, the work around as mentioned is to use lerna run prepublish && lerna run prepare but yes, I agree that it does not require work on lerna side but at yarn side.

Hopefully your comments and mine here for now will help with others who approach this as well.

stale

stale commented on Dec 27, 2018

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

evocateur

evocateur commented on Jan 2, 2019

@evocateur
Member

Closing as a duplicate of #1125

lock

lock commented on Apr 2, 2019

@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.

locked as resolved and limited conversation to collaborators on Apr 2, 2019
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @evocateur@ForbesLindesay@davidhouweling

        Issue actions

          lerna bootstrap failing as a postinstall step with yarn workspaces · Issue #1308 · lerna/lerna