question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lerna publish with prepublishOnly executes in leaf

See original GitHub issue

When running lerna publish, it fails at prepublishOnly script as it runs on the leaf only instead from root.

Expected Behavior

lerna publish should run prepublishOnly script from root similar to lerna exec --scope <component> npm publish

Current Behavior

It fails at prepublishOnly script as it requires some binaries linking and we use lerna bootstrap --nohoist which doesn’t creates any .bin files like in lerna@2version.

And hence it fails

package.json

  "scripts": {
    "prepublishOnly": "npm run build",
    "build": "npm run build:clean && npm run build:lib",
    "build:clean": "rimraf lib",
    "build:lib": "webpack"
}

Error

> rimraf lib

sh: rimraf: command not found

The rmraf exist in the root node_modules but not in the leaf.

cmd (here lerna is an external command)

lerna publish 

but following run as expected when running through the script

 lerna publish --cd-version=prerelease --force-publish=* --no-verify-access

Possible Solution

Steps to Reproduce (for bugs)

lerna.json

<!-- Please paste your `lerna.json` here -->

lerna-debug.log

<!-- If you have a `lerna-debug.log` available, please paste it here -->
<!-- Otherwise, feel free to delete this <details> block -->

Context

Your Environment

Executable Version
lerna --version 3.13.0
npm --version VERSION
yarn --version VERSION
node --version VERSION
OS Version
NAME VERSION

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
veeramarnicommented, Feb 19, 2019

I mean my issue was, the lerna doing differently when we run lerna command externally. For example (works fine):

package.json

  "scripts": {
    "publish": "lerna version --conventional-commits && lerna publish from-package --conventional-commits",
}

Which runs publish script in all the packages as expected and we don’t get any errors.

But when we ran through the external command like (here lerna was from global npm package)

lerna version --conventional-commits && lerna publish from-package --conventional-commits

It fails with the following error.

> rimraf lib

sh: rimraf: command not found

I understand, in leaf nodes, we need dev dependency on rimraf but I was expecting it would run from the root in both cases. Maybe I’m missing something here as I’m curious to find why it runs through the scripts without error otherwise not.

0reactions
evocateurcommented, Oct 5, 2019

Don’t use a global installation of lerna, only use a local install in the root devDependencies. npx lerna if you must run the commands outside of npm scripts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@lerna/publish | Yarn - Package Manager
When you run the new command lerna repair , lerna will execute a series of code migrations/codemods which update your workspace to the...
Read more >
Lerna: Documentation
Lerna is a fast modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
Read more >
How to npm publish specific folder but as package root
now when you run publish command npm involve prepublishOnly . It builds files and saves them to lib folder (a build script depend...
Read more >
JavaScript @lerna/run-lifecycle getOrderedCalls Examples
it("does not duplicate rooted leaf scripts", async () => { const cwd = await initFixture("lifecycle-rooted-leaf"); await lernaPublish(cwd)(); ...
Read more >
How to set up a TypeScript monorepo and make Go ... - Medium
Firstly, when publishing a single package (with independent versioning), lerna won't run the prepublishOnly script for its dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found