ngcc fails in monorepo setup with libraries built with view engine and consumed with tsconfig paths
See original GitHub issue🐞 bug report
Affected Package
Probably @angular-devkit/build-angular or @angular/compiler.
Is this a regression?
Works with v8.
Description
We are using a monorepo setup with 1 application and two libraries. One library gets published and one is private. In short:
- lib1 component library published to internal nexus
- lib2 private to the monorepo consuming lib1
- documentation app for lib1 consuming both lib1 and lib2, in the reproduction sample it only consumes lib2 for simplicity
- for the application build we point to the build artifacts in the
distfolder via tsconfig paths
I created a simple reproduction repository: https://github.com/Phil147/ngcc-monorepo/tree/rc6 https://github.com/Phil147/ngcc-monorepo/tree/master with RC8
Lib1 has a secondary entry point for a button component. Lib2 uses the button in a component. Both libraries build correctly but then ngcc fails during the application build.
Run npm run build:all which will build the libraries and then the application, all in production mode meaning the libraries with view engine.
In the rc6 branch the error is
ERROR in Failed to compile entry-point lib2 due to compilation errors:
dist/lib1/button/button.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of Lib2Module, but could not be resolved to an NgModule class
1 export declare class ButtonModule {
On the master branch with rc8:
ERROR in Cannot read property 'injectorImports' of undefined
🔬 Minimal Reproduction
https://github.com/Phil147/ngcc-monorepo/tree/rc6 https://github.com/Phil147/ngcc-monorepo/tree/master
Run npm ci and npm run build:all on both branches to see the errors.
🔥 Exception or Error
ERROR in Failed to compile entry-point lib2 due to compilation errors:
dist/lib1/button/button.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of Lib2Module, but could not be resolved to an NgModule class
1 export declare class ButtonModule {
ERROR in Cannot read property 'injectorImports' of undefined
🌍 Your Environment
Angular Version:
Angular CLI: 9.0.0-rc.8
Node: 12.13.0
OS: darwin x64
Angular: 9.0.0-rc.8
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.900.0-rc.8
@angular-devkit/build-angular 0.900.0-rc.8
@angular-devkit/build-ng-packagr 0.900.0-rc.8
@angular-devkit/build-optimizer 0.900.0-rc.8
@angular-devkit/build-webpack 0.900.0-rc.8
@angular-devkit/core 9.0.0-rc.8
@angular-devkit/schematics 9.0.0-rc.8
@ngtools/webpack 9.0.0-rc.8
@schematics/angular 9.0.0-rc.8
@schematics/update 0.900.0-rc.8
ng-packagr 9.0.0-rc.3
rxjs 6.5.3
typescript 3.6.4
webpack 4.41.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:15 (8 by maintainers)

Top Related StackOverflow Question
For others who might find this in regards to install a snapshot build: I only got it running with
npm i git://github.com/angular/compiler-cli-builds.git#be5a9df8d5759975533849e268b4191c5465efecjust using the URL in the package.json gave me some errors like@petebacondarwin Thanks for your awesome work our monorepo built successfully with ivy for the first time 🎉 💪 this is awesome. The documentation app for our library went down from 3,4 to 2,3 MB in bundle size. You guys are really awesome! 🙏
Guys, i have some solution but im not sure how currect it is.
Before do this refactoring, application size is: 18 440KB; After: 17 887KB