question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 dist folder 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
Phil147commented, Feb 8, 2020

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#be5a9df8d5759975533849e268b4191c5465efec just using the URL in the package.json gave me some errors like

npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: https://github.com/angular/compiler-cli-builds/tree/be5a9df8d5759975533849e268b4191c5465efec.
npm ERR! package.json npm can't find a package.json file in your current directory.

@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! 🙏

2reactions
ARTWINPROcommented, Feb 10, 2020

Guys, i have some solution but im not sure how currect it is.

1. "buildOptimizer": false,
2. "enableIvy": true
3. "aot": false,

Before do this refactoring, application size is: 18 440KB; After: 17 887KB

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular CLI 9 (Ivy) App build with local library (mono-repo ...
This throws off the ngcc compiler, which assumes the base tsconfig is just tsconfig.json. So if you have ngcc setup as a postinstall...
Read more >
error: failed to initialize angular compilation - ngcc failed.
After upgrading to Angular 12 getting Error: NGCC failed ... in monorepo setup with libraries built with view engine and consumed with tsconfig...
Read more >
Creating libraries - Angular
The Angular CLI uses the tsconfig paths to tell the build system where to find the ... A library or an application built...
Read more >
Getting Started with Monorepo with Nx Nrwl - Rupesh Tiwari
What NX CLI does? Using Nx CLI over Angular CLI; How to opt out of NX CLI; Understanding NX Workspace Scripts; Creating Angular...
Read more >
Compiling Angular Libraries Properly in a Multi-Framework ...
We discovered the meaning behind the error and why it was happening: Angular uses its own CLI. Among other things, the Angular CLI...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found