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.

[Bug] Angular builder cannot find built dependent libs

See original GitHub issue

Prerequisites

  • I am running the latest version
  • I checked the documentation (nx.dev) and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behavior

Builder @nrwl/angular:package should be able to locate built dependent libraries in custom locations (not in dist/libs/<lib-name>) if library output path was changed in it’s ng-package.json’s dest property.

Current Behavior

Right now builder @nrwl/angular:package has hardcoded path to resolve all dependent libs from path that looks like dist/libs/<lib-name>:

https://github.com/nrwl/nx/blob/f232a438d3ed5a10235d278b0f0e4573c19d14dc/packages/angular/src/builders/package/package.impl.ts#L55-L60

Failure Information (for bugs)

When building a library via @nrwl/angular:package builder that has another library as dependency that is also built with @nrwl/angular:package and it’s output path was modified then build fails with:

Some of the library button's dependencies have not been built yet. Please build these libraries before:
- utils

Try: nx run-many --target build --projects button,...

Steps to Reproduce

  1. Create empty NX workspace
  2. Generate a publishable angular library called lib1
  3. Generate a publishable angular library called lib2
  4. Import NgModule from lib1 into lib2
  5. Modify ng-package.json file of lib1 to change dest property to other location (./dist) instead of default ../../dist/libs/lib1
  6. Run ng build lib1 to build dependency first
  7. Run ng build lib2 and watch it fails even when we built it’s dependency lib1

Context

>  NX  Report complete - copy this into the issue template

  @nrwl/angular : 9.0.0
  @nrwl/cli : 9.0.0
  @nrwl/cypress : 9.0.0
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.0.0
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.0.0
  @nrwl/web : Not Found
  @nrwl/workspace : 9.0.0
  typescript : 3.7.5

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
juristrcommented, Jan 8, 2021

The problem here is that the angular.json libs’ outputs property needs to be always in sync with what is in the ng-package.json as of now. We don’t sync them manually, but that needs to be done by the user in case they’re being changed.

Basically right now a lib config might look like this:

"core-publib1": {
    "projectType": "library",
    ...
    "architect": {
        "build": {
            "builder": "@nrwl/angular:package",
            "options": {
                "tsConfig": "libs/core/publib1/tsconfig.lib.json",
                "project": "libs/core/publib1/ng-package.json"
            },
        }
}

By default everything works out of the box. If someone changes the dest inside the ng-package.json, the output path Nx infers would be out of sync with what is being used by ng-packagr and thus leads to unexpected behaviours. To fix that, add the outputs property to the config in angular.json, like:

"core-publib1": {
    "projectType": "library",
    ...
    "architect": {
        "build": {
            "builder": "@nrwl/angular:package",
            "outputs": ["dist/libs/core/publib__1"], <<<<<<<<<<<< needs to be in sync with ng-package.json
            "options": {
                "tsConfig": "libs/core/publib1/tsconfig.lib.json",
                "project": "libs/core/publib1/ng-package.json"
            },
        }
}
0reactions
SurajSunarcommented, May 27, 2020

Hi Author, I am also facing same issue while building lib packages when upgraded to Angular 9. Please let me have the solution for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find module "@angular-devkit/build ... - Stack Overflow
After updating to Angular 6.0.1, I get the following error on ng serve : Could not find module "@angular-devkit/build-angular" from ...
Read more >
Creating libraries - Angular
This page provides a conceptual overview of how to create and publish new libraries to extend Angular functionality. If you find that you...
Read more >
Fixing Could not find module @angular-devkit/build-angular ...
Solution 1: Delete node_modules folder and run npm install · Solution 2 : Install @angular-devkit/build-angular package as a dev dependency.
Read more >
@angular-devkit/build-angular - npm
This package contains Architect builders used to build and test Angular applications and libraries. Builders. Name, Description. app-shell ...
Read more >
Resolved:Could not find @angular-devkit/build-angular:browser
This error I found to be due to a mismatch in the angular-cli framework and corresponding angular dependencies for a given project. This...
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