Skip to content

Libraries can't import stuff from one another (official solution needed) #12453

Closed
@chrillewoodz

Description

@chrillewoodz

Bug Report or Feature Request (mark with an x)

- [x] bug report/question
- [ ] feature request

Command (mark with an x)

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

Versions

Node: v8.12.0
npm: 6.4.1
ng:

@angular-devkit/architect 0.8.4
@angular-devkit/build-angular 0.8.4
@angular-devkit/build-ng-packagr 0.8.4
@angular-devkit/build-optimizer 0.8.4
@angular-devkit/build-webpack 0.8.4
@angular-devkit/core 0.8.4
@angular-devkit/schematics 0.8.4
@angular/cli 6.2.4
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.2.4
@schematics/angular 0.8.4
@schematics/update 0.8.4
ng-packagr 4.2.0
rxjs 6.2.2
typescript 2.9.2
webpack 4.20.2

Repro steps

  1. ng new my-app
  2. ng generate library @internal/core
  3. ng generate library @internal/types
  4. Expose something from EACH library
  5. Import something from @internal/core into @internal/types and vice versa.
  6. ng build @internal/types or ng build @internal/core

The log given by the failure

BUILD ERROR
projects/internal/types/src/lib/interfaces/click-outside-instance.interface.ts(1,37): error TS2307: Cannot find module '@internal/core'.

Error: projects/internal/types/src/lib/interfaces/click-outside-instance.interface.ts(1,37): error TS2307: Cannot find module '@internal/core'.

    at Object.<anonymous> (/Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ngc/compile-source-files.js:40:68)
    at Generator.next (<anonymous>)
    at /Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12)
    at Object.compileSourceFiles (/Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ngc/compile-source-files.js:17:12)
    at Object.<anonymous> (/Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:31:32)
    at Generator.next (<anonymous>)
    at /Users/cardhock/web-projects/@internal/packages/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71
    at new Promise (<anonymous>)

Desired functionality

It should automatically build both projects without manually having to add a bunch of hacks.

Mention any other details that might be useful

I've gone through every issue regarding this issue but nothing helps, I keep getting the same error.

#10444
#10615
#10780

Are some of the issues I've looked at.

They talk about using paths in compilerOptions in each lib's tsconfig.lib.json file, I've done this:

@internal/core:

  "compilerOptions": {
    "paths": {
      "@internal/types": [
        "dist/types", // mostly for the IDE
        "../../dist/types", // for the app
        "../../../dist/types" // for another lib
      ]
    }
  }

@internal/types:

  "compilerOptions": {
    "paths": {
      "@internal/core": [
        "dist/core", // mostly for the IDE
        "../../dist/core", // for the app
        "../../../dist/core" // for another lib
      ]
    }
  }

But when I build.. it's like I've done nothing at all.

I'm not sure if this happens mostly because none of the libraries have been built so when you're trying to import something it's not actually there, if so this sounds like a bug to me. If it finds a dependency that's not yet been built it should build it.

Can the official solution please be added somewhere on how you get scoped libraries to work with one another, preferably in the story? https://github.com/angular/angular-cli/wiki/stories-create-library

I'm completely stuck on this and I don't know what to do unless I get proper help here. Please help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions