store: 🐞[BUG]: Ivy build error
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => https://github.com/ngxs/store/blob/master/CONTRIBUTING.md
[ ] Other...
Current behavior
Angular cli can not compiled with Ivy (ng serve works): node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng build --prod
ERROR in ./src/app/authenticated-users/inventory/inventory.module.ts 49:21-41
"export 'NgxsFeatureModule' (imported as 'i1') was not found in '@ngxs/store'
ERROR in ./src/app/authenticated-users/cashier/cashier.module.ts 49:24-44
"export 'NgxsFeatureModule' (imported as 'i1') was not found in '@ngxs/store'
ERROR in ./src/store/store.module.ts 31:79-96
"export 'NgxsRootModule' (imported as 'i1') was not found in '@ngxs/store'
Expected behavior
Angular cli can compiled with Ivy
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
Libs:
- @angular/core version: ^8.2.0-next.1
- @ngxs/store version: ^3.3.2
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
- [x] Opera 62.0.3331.72
For Tooling issues:
- Node version: v12.6.0.
- Platform: Linux Ubuntu 16.4
Others:
Azure
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 40 (22 by maintainers)
@JoostK looked into this. Angular’s DI cannot resolve the parameters of the constructor because
AuthenticationState
is only decorated with@State
. Decorate it with@Injectable
and everything should work as expected.https://www.ngxs.io/advanced/ivy-migration-guide
https://github.com/freemanlam/ng9-ngxs-di-issue/blob/master/src/app/test.state.ts
Works
Router plugin does not support with Ivy
I can confirm by adding @Injectable() before @State(…) it’s working with angular 9 rc0
@unlight thanks, that is interesting. I was able to reproduce your issue and found an issue with ngcc’s processing of private exports.
Previously (pre-Ivy), the compiler would create a private export for all non-public exports, as doing so allows the non-public exports to be referenced outside of the library using their private export that the compiler created. The Ivy compiler also needs to create imports for things imported from a library, but is unaware of the private exports (they were only considered in the pre-Ivy compiler). To remedy this, ngcc analyzes the program to find all non-public exports that the Ivy compiler may need to create references to, and updates the program and declaration files by adding the necessary exports.
After the declaration files have been adjusted during the first run of ngcc, say ES2015, and then the library’s ES5 bundle is processed, ngcc will look at the declaration files to determine which exports it needs to add. Since the declaration files have already been updated when running ES2015, it will incorrectly omit the insertion of the private exports to the ES5 bundle. This is where the
export 'NgxsFeatureModule' (imported as 'ɵngcc1') was not found in '@ngxs/store'
error comes from.I was able to workaround this issue when only the ES5 bundle was processed, but this is an issue that needs to be resolved in ngcc itself.
Gentlemen, tested with 9.0.0-next.7 and it works:
AOT works as well.
cc @ngxs/core
I have the same problem than @splincode for Router plugin. All Ngxs package are
3.5.0
. Typescript3.5.3
. All Angular8,2,0
This issue has been reported to the angular team: https://github.com/angular/angular/issues/31791
PS. This is not really possible to reproduce in StackBlitz so @arturovt made a repo here: https://github.com/arturovt/ivy-ngxs-repro
Worked with Angular 9-rc.7
Here’s a PR that should fix the
export 'NgxsFeatureModule' (imported as 'ɵngcc1') was not found in '@ngxs/store'
issue: https://github.com/angular/angular/pull/32902@ErazerBrecht This works if you target
es2015
, but it doesn’t work withes5
.Awesome, I really forgot this change in ng9, thanks 😛
As a workaround keep the current es2015 target and rely on the downleveling with differential loading that Angular CLI performs once it generates the es2015 bundles.
https://github.com/ngxs/store/issues/1165#issuecomment-514107343
Looks like for non-lazy it doesn’t work too for me