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 run` doesn't execute peers in topological order

See original GitHub issue

I have several packages, most of which only depend on the core package at the moment. Each package is individually built using the Angular CLI.

  • @denverhjs/core
  • @denverhjs/foo
  • @denverhjs/baz
  • @denverhjs/bat

Expected Behavior

Lerna can determine that @denverhjs/core must be built before any of the packages that list it in their package.json peerDependencies list.

Current Behavior

Executing the build script yields the following error output:

lerna ERR! npm run build stderr: src/lib/bat.module.ts(3,37): error TS2307: Cannot find module ‘@denverhjs/core’. src/lib/bat.module.ts(8,5): Error during template compile of ‘BatModule’ Could not resolve @denverhjs/core relative to [object Object]… src/lib/bat.module.ts(8,5): Error during template compile of ‘BatModule’ Could not resolve @denverhjs/core relative to [object Object]…

Error: src/lib/bat.module.ts(3,37): error TS2307: Cannot find module ‘@denverhjs/core’. src/lib/bat.module.ts(8,5): Error during template compile of ‘BatModule’ Could not resolve @denverhjs/core relative to [object Object]… src/lib/bat.module.ts(8,5): Error during template compile of ‘BatModule’ Could not resolve @denverhjs/core relative to [object Object]…

at Object.<anonymous> (/Users/denverb/workspace/personal/lerna-demo/node_modules/ng-packagr/lib/ngc/compile-source-files.js:65:19)
at Generator.next (<anonymous>)
at fulfilled (/Users/denverb/workspace/personal/lerna-demo/node_modules/ng-packagr/lib/ngc/compile-source-files.js:4:58)
at <anonymous>

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @denverhjs/bat@0.0.1 build: ng build bat npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @denverhjs/bat@0.0.1 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in: npm ERR! /Users/denverb/.npm/_logs/2019-03-25T18_53_54_969Z-debug.log

lerna ERR! npm run build exited 1 in ‘@denverhjs/bat’ lerna WARN complete Waiting for 3 child processes to exit. CTRL-C to exit immediately. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! lerna-demo@0.0.0 build: lerna run build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the lerna-demo@0.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/denverb/.npm/_logs/2019-03-25T18_53_55_004Z-debug.log

Possible Solution

Execution proceeds without error when the command: lerna run build --scope @denverhjs/core && lerna run build --ignore @denverhjs/core

However that is not sustainable as the dependency graph grows in depth.

Steps to Reproduce (for bugs)

  1. Fork and clone this repo: https://github.com/denver-HJS/lerna-demo
  2. execute npm run build or lerna run build
lerna.json

{
  "packages": [
    "projects/*"
  ],
  "version": "independent"
}

Context

I’m trying to leverage this great library to provide a CI solution for an Angular monorepo that contains multiple Angular NPM packages.

Your Environment

Executable Version
lerna --version 3.13.1
npm --version 6.4.0
node --version 9.11.1
OS Version
NAME VERSION
macOS Sierra 10.13.6
Windows 10 1607

Issue Analytics

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

github_iconTop GitHub Comments

11reactions
denver-HJScommented, May 14, 2019

@evocateur, thank you for reading that closer than I did! 😃

It does work correctly now when I’ve added the desired higher order dependency to the leaf packages’ devDependencies list. Thank you for the help.

9reactions
deviator206commented, Apr 2, 2019

I have similar issue where in there packages |- module#1 |- module#2 |- module#3

now when I try to run lerna run build Since module#3 is marked as dependency of module#1, command build needs to be executed first for module#3 so it to be available for consumption for module#1

Question - Is this supported in lernaJS ? If yes, how can i achieve it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lerna specify run order - Stack Overflow
From the root folder, I run lerna run build . It seems to run build of the packages in the alphabetically order. Is...
Read more >
@lerna/list | Yarn - Package Manager
Cycles are broken on a best-effort basis in a way not guaranteed to be consistent across Lerna invocations. Topological sorting can cause concurrency ......
Read more >
Untitled
When you run `lerna publish`, if a module has been updated since the last time ... all tasks execute on packages in topologically...
Read more >
Things I wish I had known when I started JavaScript monorepo ...
A word on topology​​ Lerna will find out which packages have build npm script defined and then it determines their order of execution....
Read more >
lerna/publish - npm.io
Pass all to include both dependencies and devDependencies when constructing the package graph and determining topological order. When using traditional peer + ...
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