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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library importing another library's module results in build error #14164

Closed
atodd-geoplan opened this Issue Apr 15, 2019 · 8 comments

Comments

Projects
None yet
2 participants
@atodd-geoplan
Copy link

atodd-geoplan commented Apr 15, 2019

馃悶 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

@alan-agius4

This comment has been minimized.

Copy link
Collaborator

alan-agius4 commented Apr 15, 2019

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

alan-agius4 added a commit to alan-agius4/ng-packagr that referenced this issue Apr 15, 2019

fix: emit ts option diagnostic
In some cases, when a direct dependency is not build we are not emitting an error and rollup would would because the entrypoint cannot be resolved.

Closes angular/angular-cli#14164
@atodd-geoplan

This comment has been minimized.

Copy link
Author

atodd-geoplan commented Apr 15, 2019

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

alan-agius4 added a commit to ng-packagr/ng-packagr that referenced this issue Apr 15, 2019

fix: emit ts option diagnostic
In some cases, when a direct dependency is not build we are not emitting an error and rollup would would because the entrypoint cannot be resolved.

Closes angular/angular-cli#14164
@alan-agius4

This comment has been minimized.

Copy link
Collaborator

alan-agius4 commented Apr 15, 2019

@atodd-geoplan

This comment has been minimized.

Copy link
Author

atodd-geoplan commented Apr 15, 2019

@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

This comment has been minimized.

Copy link
Author

atodd-geoplan commented Apr 15, 2019

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

@alan-agius4

This comment has been minimized.

Copy link
Collaborator

alan-agius4 commented Apr 15, 2019

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 ng-packagr/ng-packagr#1264

Thanks.

@atodd-geoplan

This comment has been minimized.

Copy link
Author

atodd-geoplan commented Apr 15, 2019

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

@alan-agius4

This comment has been minimized.

Copy link
Collaborator

alan-agius4 commented Apr 15, 2019

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",
      ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.