ng-packagr: Problem in a multiple library repo: can't inter-depend on each other

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

If I create a repo made of two libraries for which one depends on the other I can’t figure out how to package the one that depends on the other. I get the error shown below.

How To Reproduce

I have a repo setup here. The libraries are in the packages folder. Note that ng-date-utils depends on ng-utils. But I get this error trying to package ng-date-utils.

cuervomovil:au-ng ken$ node_modules/.bin/ng-packagr -p packages/ng-date-utils/ng-package.json
Building Angular library
Generating bundle for @animalus/ng-date-utils
Cleaning bundle build directory
Processing assets
Running ngc

BUILD ERROR
Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/src/dateUtils.service.ts:10:27: Cannot find module '../../ng-utils/public_api'.
Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/src/module.ts:4:23: Cannot find module '../../ng-utils/public_api'.
Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/ng-date-utils.ts:7:45: Cannot find module '../ng-utils/public_api'.
Error: Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/src/dateUtils.service.ts:10:27: Cannot find module '../../ng-utils/public_api'.
Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/src/module.ts:4:23: Cannot find module '../../ng-utils/public_api'.
Error at /Users/ken/dev/animalus/au-ng/packages/ng-date-utils/.ng_pkg_build/@animalus-ng-date-utils/ts/ng-date-utils.ts:7:45: Cannot find module '../ng-utils/public_api'.
    at new UserError (/Users/ken/dev/animalus/au-ng/node_modules/ng-packagr/node_modules/@angular/tsc-wrapped/src/tsc.js:27:28)
    at check (/Users/ken/dev/animalus/au-ng/node_modules/ng-packagr/node_modules/@angular/tsc-wrapped/src/tsc.js:93:15)
    at Tsc.typeCheck (/Users/ken/dev/animalus/au-ng/node_modules/ng-packagr/node_modules/@angular/tsc-wrapped/src/tsc.js:173:9)
    at /Users/ken/dev/animalus/au-ng/node_modules/ng-packagr/node_modules/@angular/tsc-wrapped/src/main.js:122:23
    at <anonymous>

Expected Behaviour

please describe what behaviour or result you expected

Version Information

ng-packagr: v1.x.y
node: v8.x.y
@angular: v4.x.y
rxjs:
zone.js:

please include any version information that might be relevant, e.g. other third-party libraries

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Using the programmatic API, we are able to package the libraries in order, and during the packaging we are able to use the already packaged libraries. This packaging process uses a custom tsconfig that looks for the libraries in the place they are packaged to. The order of packaging is very important, as the libs with dependencies must package after the dependecies have finished packaging. Something like:

await ngPackagr()
    .forProject('/usr/local/lib-1/package.json')
    .withTsConfig('tsconfig.packagr.json')
    .build();

await ngPackagr()
    .forProject('/usr/local/lib-2-that-depends-on-lib-1/package.json')
    .withTsConfig('tsconfig.packagr.json')
    .build();

Please check the ngPackagr code for the exact API here: https://github.com/dherges/ng-packagr/blob/v2.4.1/src/lib/ng-v5/packagr.ts

Hi guys is possible avoid the use of link?

i find out a plugin for rollup that could avoid this thing:

https://www.npmjs.com/package/rollup-plugin-paths

but I am not sure if there is a way to include plugin in ng-packagr , someone knows if is something possible?

Thank you! I found that it doesn’t work exactly like that though. I had to do both parts of the linking process. In your nomenclature…

cd packages/lib-a/dist
yarn link
cd ../../..
yarn link lib-a

…which for my repo was solved with the following scripts in the package.json…

    "build:utils": "ng-packagr -p packages/ng-utils/package.json && cd packages/ng-utils && yarn link && cd ../.. && yarn link @animalus/ng-utils",
    "build:date-utils": "ng-packagr -p packages/ng-date-utils/package.json",
    "build": "yarn run build:utils && yarn run build:date-utils"

I also found out the hard way (in that it took me a while to find out why it wasn’t working) that you can’t mix npm link and yarn link commands as they use different global directories to store the links in!

Thanks!

@crowmagnumb you need to use npm link or yarn link. you also need to make sure to package them in the correct order. so for example. in a situation where lib-b depends on lib-a

# Build Package A
ng-packagr -p packages/lib-a 
# Link the output
npm link packages/lib-a/dist
# Now lib-b can reference lib-a and will build correctly
ng-packagr -p packages/lib-b

@mezoistvan awesome that the API opens up the possibility for dependencies for a multi-library repo.

How would this work for Secondary Entry Points, it seems like an overkill to have to suddenly add a full package.json for each entry point. NPM also doesn’t allow the name property to be like @angular/material/button.

Would be great if we can make Secondary Entry Points depend on each other. If there is already a way, would love to know how I could achieve this…

Thanks in advance!

OK, my bad. Sorry. You know how you set up automation, then come to rely on it, and then not really pay attention to it because well it’s all automated right? Well, I just did that. I had automated the linking of the package after building, but then I later moved the location of where the package gets built to but did not update the linking code. So it kept linking to the old place and I didn’t notice. Sorry, this still works. Closing again…