Ivy: NGCC incorrectly compiles the "@ngxs/router-plugin" as UMD
See original GitHub issueπ bug report
Affected Package
Is this a regression?
Yes
Description
The NGCC incorrectly compiles the @ngxs/router-plugin as UMD.
π¬ Minimal Reproduction
https://github.com/arturovt/ivy-ngxs-router-plugin-umd-repro
- clone and install dependencies
- check the
postinstallscript
Or open the node_modules/@ngxs/router-plugin/bundles/ngxs-router-plugin.umd file in your IDE and see the generated code at the end of the factory(....) function. This has to be something like global...modules.ngxsFeature.module.
Providing screenshot below (this is how it looks like on my PC):

π Your Environment
Angular Version:
Angular CLI: 9.0.0-rc.4
Node: 12.11.1
OS: linux x64
Angular: 9.0.0-rc.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.0-rc.4
@angular-devkit/build-angular 0.900.0-rc.4
@angular-devkit/build-optimizer 0.900.0-rc.4
@angular-devkit/build-webpack 0.900.0-rc.4
@angular-devkit/core 9.0.0-rc.4
@angular-devkit/schematics 9.0.0-rc.4
@ngtools/webpack 9.0.0-rc.4
@schematics/angular 9.0.0-rc.4
@schematics/update 0.900.0-rc.4
rxjs 6.5.3
typescript 3.6.4
webpack 4.41.2
UPD
I could guess that it emits such code due to the inability to compile this package at all. The compiler behaves differently, because:
- in 80% of cases it compiles without errors and generates such code
- in 20% of cases it throws during compilation with:
Error: Error on worker #1: Error: Failed to compile entry-point @ngxs/router-plugin due to compilation errors:
node_modules/@ngxs/router-plugin/bundles/ngxs-router-plugin.umd.js(1034,34): error TS-991010: Value at position 0 in the NgModule.imports of NgxsRouterPluginModule is not a reference: [object Object]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:20 (19 by maintainers)
Top Results From Across the Web
error: failed to initialize angular compilation - ngcc failed.
The NGCC incorrectly compiles the @ngxs/router-plugin as UMD. Minimal Reproduction. https://github.com/arturovt/ivy-ngxs-router-plugin-umd-repro. clone andΒ ...
Read more >Angular 11 is not running ngcc - ivy - Stack Overflow
My problem was that an another tsconfig file was overwriting the root's definitions, and turned off ivy and ngcc altogether.
Read more >After upgrading to Angular 10, ivy ngcc is compiling as a esm5 ...
After upgrading to Angular 10, ivy ngcc is compiling as a esm5, umd modules. My Environnement: ngular CLI: 10.2.0 Node: 12.15.0 OS: win32Β ......
Read more >The Angular linker (goodbye ngcc!) - Ninja Squad
Angular 11.1 introduced a new compilation mode. It allows to partially compile a library before shipping it to NPM. What does that mean?...
Read more >Angular Ivy
CLI commands run ngcc as needed when performing an Angular build. ... See the Creating Libraries guide for more on how to compile...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

OK so now that #34356 has landed, I believe that #34254 should be enough to fix this package, assuming that you are using the latest
devversion of the package. Hopefully it will be merged this week and appear in the next RC next week.Updating Angular to use the artifacts from https://github.com/angular/angular/pull/34254 removes this error and the ngcc processing seems to complete without error.
That being said I now see that it adds an incorrect export into the
node_modules/@ngxs/store/ngxs-store.d.tsfile:It is confusing the public export from this file:
with the exports from the referenced files.