angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Library importing another library's module results in build error

Open atodd-geoplan opened this issue 7 years ago β€’ 10 comments

🐞 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

atodd-geoplan avatar Apr 15 '19 08:04 atodd-geoplan

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

alan-agius4 avatar Apr 15 '19 09:04 alan-agius4

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

atodd-geoplan avatar Apr 15 '19 09:04 atodd-geoplan

Looking at the tsconfig, you are referencing the distribution

https://github.com/alastair-todd/ng-cli-lib-bug/blob/f4c24d9d62626aed41cd77980ee8090d5fe146aa/tsconfig.json#L21-L33

alan-agius4 avatar Apr 15 '19 09:04 alan-agius4

@alan-agius4 why does it matter? two imports one with the projects path 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?

atodd-geoplan avatar Apr 15 '19 09:04 atodd-geoplan

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

atodd-geoplan avatar Apr 15 '19 10:04 atodd-geoplan

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 avatar Apr 15 '19 11:04 alan-agius4

@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?

atodd-geoplan avatar Apr 15 '19 12:04 atodd-geoplan

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",
      ],

alan-agius4 avatar Apr 15 '19 13:04 alan-agius4

You can always use nrwl :)

hevans90 avatar Jul 16 '19 13:07 hevans90

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.