Angular-cli: Library importing another library's module results in build error

Created on 15 Apr 2019  路  10Comments  路  Source: angular/angular-cli

馃悶 Bug report

Command (mark with an x)


- [ ] new
- [x ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Not for me - new workspace

Description

When importing a module from one library into a module of another library, using either the public-api, the distribution folder or relative paths will trigger a build error when building the library that is doing the import

ng build two

Also, the error is cryptic and had to trial and error to find the culprit.

馃敩 Minimal Reproduction

Create a workspace with a new app and two libraries.
Import library two's module into library one's.
Build library one.

see: https://github.com/alastair-todd/ng-cli-lib-bug

馃敟 Exception or Error


BUILD ERROR
Could not resolve entry (F:\_dev\ng-work\dist\two\esm2015\two.js)
Error: Could not resolve entry (F:\_dev\ng-work\dist\two\esm2015\two.js)
    at error (F:\_dev\ng-work\node_modules\rollup\dist\rollup.js:3460:30)
    at F:\_dev\ng-work\node_modules\rollup\dist\rollup.js:21474:17

Could not resolve entry (F:\_dev\ng-work\dist\two\esm2015\two.js)
Error: Could not resolve entry (F:\_dev\ng-work\dist\two\esm2015\two.js)
    at error (F:\_dev\ng-work\node_modules\rollup\dist\rollup.js:3460:30)
    at F:\_dev\ng-work\node_modules\rollup\dist\rollup.js:21474:17

馃實 Your Environment


Angular CLI: 7.3.8
Node: 10.13.0
OS: win32 x64
Angular: 7.2.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.8
@angular-devkit/build-angular      0.13.8
@angular-devkit/build-ng-packagr   0.13.8
@angular-devkit/build-optimizer    0.13.8
@angular-devkit/build-webpack      0.13.8
@angular-devkit/core               7.3.8
@angular-devkit/schematics         7.3.8
@angular/cli                       7.3.8
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.3.8
@schematics/angular                7.3.8
@schematics/update                 0.13.8
ng-packagr                         4.7.1
rxjs                               6.3.3
typescript                         3.2.4
webpack                            4.29.0

Most helpful comment

At the moment, the only supported way is to build the library first.

You can add path references, but these are only supported by the IDEs and trying to build the second library before the first will still result in a build failure.

Example:

      "one": [
        "dist/two",
        "projects/one/src/public-api.ts"
      ],
      "one/*": [
        "projects/one/*",
        "projects/one/*/src/public-api.ts",
      ],

All 10 comments

The issue seems to be that you are not building library 1 before library 2.

@alan-agius4 this makes no odds which makes sense since I'm using the projects path to reference them rather than distribution

@alan-agius4 why does it matter? twoimports onewith the projectspath
import { OneModule } from "projects/one/src/lib/one.module";

not the paths shortcuts

updating or deleting those paths has zero effect

i think you have been a bit trigger happy closing this so quickly?

@alan-agius4 did you try building twoafter building one ceteris paribus?

Hi @atodd-geoplan.

The above mentioned import import { OneModule } from "projects/one/src/lib/one.module"; is not valid because you are referencing TypeScript files which are outside of the current compilation root directory.

When you reference a file in another library, you always need to use the library name as in the import path example import { OneModule } from "one".

In addition, at the moment ng-packagr doesn't support having a different rootDir, and this issue is similar open issue at upstream https://github.com/ng-packagr/ng-packagr/issues/1264

Thanks.

@alan-agius4 thanks for the explanation. now I understand and it works.

is this then the standard for importing a local library into a local ng app?

could i choose to reference projects in the paths instead - or it must be a build target?

At the moment, the only supported way is to build the library first.

You can add path references, but these are only supported by the IDEs and trying to build the second library before the first will still result in a build failure.

Example:

      "one": [
        "dist/two",
        "projects/one/src/public-api.ts"
      ],
      "one/*": [
        "projects/one/*",
        "projects/one/*/src/public-api.ts",
      ],

You can always use nrwl :)

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings