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

[Bug] Angular builder cannot find built dependent libs #2479

Closed
4 tasks done
gund opened this issue Feb 13, 2020 · 6 comments
Closed
4 tasks done

[Bug] Angular builder cannot find built dependent libs #2479

gund opened this issue Feb 13, 2020 · 6 comments
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@gund
Copy link

gund commented Feb 13, 2020

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>:

const packageJsonPath = join(
context.workspaceRoot,
'dist',
libDep.node.data.root,
'package.json'
);

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
@gund
Copy link
Author

gund commented Feb 13, 2020

So angular builder should resolve package.json by looking at ng-package.json's dest property that is located in angular.json's project option of the build target.

The steps should be:

  1. Locate ng-package.json first from angular.json:
"architect": {
  "build": {
    "builder": "@nrwl/angular:package",
    "options": {
      "tsConfig": "libs/utils/tsconfig.lib.json",
      "project": "libs/utils/ng-package.json" // <-- Locate ng-package.json first
    }
  },
}
  1. Read ng-package.json's dest property to find destination path:
{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "./dist", // <-- Read this prop
  "lib": {
    "entryFile": "src/index.ts"
  }
}

Now we can use that path to find package.json of built dependency.

Please let me know if this is enough - I might work on PR for this change =)

@gund gund changed the title [Bug] Angular builder missing outputPath option [Bug] Angular builder cannot find built dependent libs Feb 13, 2020
gund added a commit to spryker/ui-components that referenced this issue Feb 13, 2020
Now all libs build into global `dist` folder due to bug nrwl/nx#2479
gund added a commit to spryker/ui-components that referenced this issue Feb 13, 2020
Now all libs build into global `dist` folder due to bug nrwl/nx#2479
@juristr juristr self-assigned this Feb 14, 2020
@FrozenPandaz FrozenPandaz added the scope: angular Issues related to Angular support in Nx label Feb 15, 2020
@vsavkin vsavkin assigned vsavkin and unassigned juristr Feb 21, 2020
@vsavkin vsavkin added this to the next milestone Feb 21, 2020
@florianehmke
Copy link

Are there any workarounds for this?

@gund
Copy link
Author

gund commented Mar 13, 2020

@florianehmke my workaround for now is keeping the output path as default and then after build executing script to copy assets back to where I needed them.

@juristr juristr self-assigned this May 26, 2020
@SurajSunar
Copy link

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.

@vsavkin vsavkin removed this from the next milestone Jul 8, 2020
@vsavkin vsavkin removed their assignment Sep 3, 2020
@juristr
Copy link
Member

juristr commented 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"
            },
        }
}

@juristr juristr closed this as completed Jan 8, 2021
zwarag pushed a commit to zwarag/nx-poc that referenced this issue Jun 1, 2021
As stated in nrwl/nx#2479 (comment)
the "outputs" property needs to be assigned in the angular.json when a default path is changed in the ng-package.json.

However I did not change the path so I think something else is wrong here.

I opened an Issue nrwl/nx#5840.
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants