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

Closed
denver-HJS opened this issue Mar 25, 2019 · 6 comments
Closed

lerna run doesn't execute peers in topological order #2009

denver-HJS opened this issue Mar 25, 2019 · 6 comments

Comments

@denver-HJS
Copy link

denver-HJS commented Mar 25, 2019

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
@evocateur evocateur changed the title lerna run doesn't execute in topological order lerna run doesn't execute peers in topological order Mar 26, 2019
@evocateur
Copy link
Member

If they're monorepo siblings, why aren't the relationships expressed in dependencies? They'll always be released in lockstep, so it's not especially clear why the core lib needs to be a peer.

@denver-HJS
Copy link
Author

In this case it's specific to front-end development, and in particular, Angular libraries.

TL;DR:
All of these libraries depend on @angular/common, @angular/core and similarly my own libraries all rely on my core. If these were listed as dependencies the bundled JavaScript artifact the Angular CLI build creates for the dependent app would contain redundant imports of those modules bloating it's size and potentially creating collisions.

Listing them as peerDependencies allows for the dependent application to select it's own version (assuming it's within the bounds declared by the libraries it's consuming) as well as eliminate the redundancy.


Per their docs:

Use TypeScript path mapping for peer dependencies

Angular libraries should list all @angular/* dependencies as peer dependencies. This insures that when modules ask for Angular, they all get the exact same module. If a library lists @angular/core in dependencies instead of peerDependencies, it might get a different Angular module instead, which would cause your application to break.

While developing a library, you must install all peer dependencies through devDependencies to ensure that the library compiles properly. A linked library will then have its own set of Angular libraries that it uses for building, located in its node_modules folder. However, this can cause problems while building or running your application.

To get around this problem you can use TypeScript path mapping to tell TypeScript that it should load some modules from a specific location. List all the peer dependencies that your library uses in the TypeScript configuration file ./tsconfig.json, and point them at the local copy in the app's node_modules folder.


Maybe I'm misunderstanding, but I don't want these siblings to be released in lockstep. In other words I need to be able to manage and publish the @denverhjs/foo package independently of @denverhjs/core versioning and publication.

@deviator206
Copy link

deviator206 commented 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?

@Aqours
Copy link

Aqours commented May 9, 2019

packages
|- module#1
....|- package.json (npm i ../module#3, install local deps)
|- module#2
|- module#3

Install local deps in project module#1, it works fine.
It will run build script in module#3 before module#1, when you call lerna run build.

@evocateur
Copy link
Member

@denver-HJS Quoting the quoted:

While developing a library, you must install all peer dependencies through devDependencies to ensure that the library compiles properly.

This is still the case with Lerna. Specify any peerDependencies in the devDependencies of a given leaf package.json, and the topological order will be respected by lerna run.

@denver-HJS
Copy link
Author

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

wodeni added a commit to penrose/penrose that referenced this issue May 23, 2022
wodeni added a commit to penrose/penrose that referenced this issue May 24, 2022
* feat: details panel, copy update

* fix: add /

* build: make core peer dep for components

* feat: add PDF export

* feat: port inspector into browser-ui

* feat: port optimizer tab

* feat: set autostep steps

* feat: add stepsize setting

* fix: evalFn on new states

* fix: opt name

* feat: roger mode!

* fix: remove browser-ui 😄

* feat: port comp graph

* build: bump monaco version

* build: add clean scripts to packages and fix peerdep build order

reference: lerna/lerna#2009

* feat: port readable variation logic

* fix: format

* fix: lint

* fix: typecheck

* fix: format

* fix: test script

* build: downgrade monaco-vim to work with monaco-editor@0.22.3

* fix: format

* fix: resample once after prepareState

* fix: everything is vite now

except for docusaurus damnit

* build: bump monaco vim back

* fix: format

* feat: add step size setting

* docs: add IDE README

* fix: format

Co-authored-by: wodeni <wn2155@columbia.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants