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.

Unexpected calls to `build` and `clean` scripts

See original GitHub issue

With our first publish in a bit after upgrading to latest lerna, I’m noticing some unexpected behavior during the publish phase. We have a monorepo with some public (publishable) packages and some private (non-publishable) apps and had been leaning on a prepare scripts in each app ("prepare": "run-s clean build",, leaning on npm-run-all) to handle ensuring the packages were ready pre-publishing. Now when I go to publish, calls to prepare continue, but I also see the following:

lerna info Executing command in 19 packages: "yarn run clean"
...
lerna info Executing command in 20 packages: "yarn run build"

Lerna is somehow deciding it needs to run clean and build on its own (already handled by the prepare scripts), which wouldn’t otherwise be a problem except that its also running these in our non-published apps (thus greatly increasing the publish time) instead of relying on prepare in just the packages bound for our registry.

I can’t find any clues as to what’s causing this behavior after looking all through our repo and the lerna code. Any thoughts?

Expected Behavior

I suppose ideally lerna wouldn’t be calling build and clean on its own.

Steps to Reproduce (for bugs)

lerna.json

{
  "lerna": "3.13.0",
  "npmClient": "yarn",
  "useWorkspaces": true,
  "packages": [
    "apps/*",
    "package-examples/*",
    "packages/**"
  ],
  "labels": {
    "tag: new feature": ":rocket: New Feature",
    "tag: breaking change": ":boom: Breaking Change",
    "tag: bug fix": ":bug: Bug Fix",
    "tag: enhancement": ":nail_care: Enhancement",
    "tag: documentation": ":memo: Documentation",
    "tag: internal": ":house: Internal"
  },
  "version": "9.0.0-alpha.0",
  "command": {
    "publish": {
      "verifyAccess": false
    }
  }
}

Your Environment

Executable Version
lerna --version 3.13.0
npm --version VERSION
yarn --version 1.12.3
node --version 8.10.0
OS Version
macOS High Sierra 10.13.6

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
evocateurcommented, Feb 26, 2019

Lerna isn’t calling clean and build, it is calling the root prepare lifecycle (in all likelihood). It’s been doing that for over six months now. I’m just spitballing, because I can’t read your mind and see the package.json files in question…

0reactions
merrywhethercommented, Apr 10, 2019

@jptaranto In my usage, lerna works fine with npm-run-all for basically every task on our dev Mac laptops. Many of our commands have lerna invoking npm-run-all which then invokes yarn scripts.

It doesn’t seem to work in Jenkins (maybe due to differences in how spawning works through 3 levels of invocation on our CI linux boxes?), where it has problems exiting properly for some tasks. Thus, our ci scripts look like yarn lint && yarn prettier && yarn type check && yarn test. This might also specifically be caused by the interaction of lerna, npm-run-all, and jest in our CI environment.

It also does not work locally in our setup for any publish lifecycle methods, as I originally described when I opened the issue, but I chalked this up to having lots of shared dev dependencies listed in the root package.json (including npm-run-all).

@evocateur What do you mean you don’t run build or clean tasks in each package? I didn’t see anything about this in the lerna docs, but am super curious about it.

For instance, we have jest configs in each leaf package’s package.json that are routinely specific to that package (same with webpack, typescript, babel, etc). Are you saying that you would run jest/webpack/etc --path-to-config=foo/... --path-to-source=foo/... directly from the root? Or are you referencing doing something more like lerna run build?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Things Go Wrong — PyArmor 7.6.0 documentation
The obfuscated script is a very simple Python script, the first line is an import statement, the second line is a function call....
Read more >
syntax error near unexpected token `(' in jenkinsfile
Syntax error near unexpected token may occur in a Jenkins job, if calling a shell script file that was stored in Jenkins credentials...
Read more >
Jobs in Azure Pipelines and TFS - Microsoft Learn
Understand jobs in Azure Pipelines, Azure DevOps Server, and Team Foundation Server (TFS)
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
#2: Reusable Workflows with Workflow Calls. Triggers are great, but this one gets a full title of its own. Now let's say you've...
Read more >
Pipeline Best Practices - Jenkins
getInstance; Cleaning up old Jenkins builds ... Using a shell script within Jenkins Pipeline can help simplify builds by ... Avoiding calls to...
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