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

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

Closed
ForbesLindesay opened this issue Mar 6, 2018 · 11 comments
Closed
Labels

Comments

@ForbesLindesay
Copy link

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
@evocateur
Copy link
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
Copy link
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
Copy link

davidhouweling commented Mar 12, 2018

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

@davidhouweling
Copy link

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

@evocateur
Copy link
Member

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

@davidhouweling
Copy link

davidhouweling commented Mar 13, 2018

@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
Copy link
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
Copy link

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
Copy link

stale bot commented Dec 27, 2018

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.

@stale stale bot added the stale label Dec 27, 2018
Hotell added a commit to Hotell/ts-setup that referenced this issue Dec 28, 2018
@evocateur
Copy link
Member

Closing as a duplicate of #1125

@lock
Copy link

lock bot commented Apr 2, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants