Nx: Error: Some of the library <YOUR LIBRARY> dependencies have not been built yet. Please build these libraries before: -testing

Created on 11 Feb 2020  ยท  6Comments  ยท  Source: nrwl/nx

We are getting this error:
Error: Some of the library "my-library" dependencies have not been built yet. Please build these libraries before: -testing

We have just upgraded to Angular 8 and are having an issue with our build.

We have two libraries generated by the Nrwl schematics (in Angular 7) within the same project. They are "my-library" and "testing".

"testing" is a library that contains nothing but stubs for Angular components that exist in "my-library". We build this library separate and place the build files in "my-library's" distribution folder. This is so we can have the following pattern in our other applications.
```
import { myComponent } from "@abc/my-library" // for components
import { myComponentStub } from "@abc/my-library/testing" // for testing

Our dist folder structure looks like this.
 dist > 
    @abc >
         my-library >
             testing > // testing directory
             package.json
             .....
We never had an issue with this error until we upgraded to angular 8 using Nx and tried to build.

**The error shows up when we do `ng build my-library`.** 

"Testing" is not a dependency used by "my-library" directly. But, the **spec** files within the library do.

They reference the stubs like so:
`Import { myComponentStub } from @abc/testing` mapped through the jest.config.

jest.config.js

...
moduleNameMapper:ย {
"@abc/testing": "../../libs/testing/src/index.ts",
},
`` The issue might lie in these test imports. The build might be looking for "@abc/testing" atdist > @abc > testing`.

Prior versions of Angular "ng build" didn't care about the spec file and their dependencies. Seeing this error is something only found in the Nx repo during a google search (angular-package.test.ts). I thought I would ask you.

Any idea how to resolve this?

core bug

Most helpful comment

After digging around through the code I was able to fix it! ๐Ÿ‘

I found out that you can define the path for the "outputs" like this:

"architect": {
  "build": {
    "builder": "@nrwl/angular:package",
    "outputs": ["component-lib/shared-utils"],
    "options": {
      "tsConfig": "libs/shared/utils/tsconfig.lib.json",
      "project": "libs/shared/utils/ng-package.json"
    }
  }
}

Without this Nx has defaulted to dist/libs/shared/utils - see: https://github.com/nrwl/nx/blob/master/packages/workspace/src/tasks-runner/utils.ts#L73

All 6 comments

Hi, sorry about this.

This was mislabeled as stale. We are testing ways to mark _not reproducible_ issues as stale so that we can focus on actionable items but our initial experiment was too broad and unintentionally labeled this issue as stale.

@FrozenPandaz I think I got a repo where this same error appears.

When adding the code in this pr my build also fails, without it it builds perfectly.

It might be something that I'm doing wrong in one of the libraries but I can't seem to spot it.

I've got the same issue. When running nx run shared-core-ui:build --with-deps Nx correctly detects that there is another lib to be built before (> NX Running target build for project shared-core-ui and its 1 deps.) and it starts even building this lib:

> ng run shared-utils:build 
Building Angular Package

After this one is successfully built, the build of the shared-core-ui lib fails:

Built shared-utils

------------------------------------------------------------------------------
Built Angular Package
 - from: libs/shared/utils
 - to:   component-lib/shared-utils
------------------------------------------------------------------------------

> ng run shared-core-ui:build 
Some of the project shared-core-ui's dependencies have not been built yet. Please build these libraries before:
- shared-utils

Try: nx run shared-core-ui:build --with-deps

โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

>  NX   ERROR  Running target "build" failed

  Failed projects:

  - shared-core-ui

Seems like the issue is that the compiled output of the first library isn't found again when building the second library. How does Nx know where to find the compiled versions of libraries? Somewhere there has to be a mapping!? ๐Ÿค”

Would be great if the error message would include the path where Nx is looking for the compiled library for easier debugging. ๐Ÿ˜‰

After digging around through the code I was able to fix it! ๐Ÿ‘

I found out that you can define the path for the "outputs" like this:

"architect": {
  "build": {
    "builder": "@nrwl/angular:package",
    "outputs": ["component-lib/shared-utils"],
    "options": {
      "tsConfig": "libs/shared/utils/tsconfig.lib.json",
      "project": "libs/shared/utils/ng-package.json"
    }
  }
}

Without this Nx has defaulted to dist/libs/shared/utils - see: https://github.com/nrwl/nx/blob/master/packages/workspace/src/tasks-runner/utils.ts#L73

Folks,

Our guide on buildable libraries doesn't cover this in depth (https://nx.dev/angular/guides/ci/incremental-builds#incremental-builds), and it probably should.

  1. Buildable libraries can only depend on other buildable libraries, and those should be built before hand. The reason: if you publish library A to npm, everything A depends on has to be published to npm as well. It cannot depend on anything in the repo it came from that wasn't published.
  2. Your testing code is part of the same library. So if it depends on something, whatever it depends on has to be built first.
  3. If Lib A depends on Lib B, Nx will use the output of B to build A. So Nx needs to find this output. It will check the outputs property first, then the outputPath option of the builder, and, finally, will default to dist/libs/libb.

Does it make sense?

Closing this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichaelWarneke picture MichaelWarneke  ยท  3Comments

SWGeekPD picture SWGeekPD  ยท  3Comments

about-code picture about-code  ยท  3Comments

danieldanielecki picture danieldanielecki  ยท  3Comments

IonFoXx picture IonFoXx  ยท  3Comments