ngxs/store

๐Ÿž[BUG]: Ivy build error

Closed this issue ยท 40 comments

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

Show stackblitz or repo example

This issue has been reported to the angular team: angular/angular#31791

PS. This is not really possible to reproduce in StackBlitz so @arturovt made a repo here:
https://github.com/arturovt/ivy-ngxs-repro

We are currently trying Ivy out in our codebase and for now it seems that ngxs 3.4.X works with Ivy.

@ErazerBrecht This works if you target es2015, but it doesn't work with es5.

Router plugin does not support with Ivy

image

I have the same problem than @splincode for Router plugin.
All Ngxs package are 3.5.0 .
Typescript 3.5.3 .
All Angular 8,2,0

Referenced Angular CLI issue seems to be resolved.

Anyone checked Ivy Compiler Compatibility with latest version of Angular 8 or 9? See that there has been some effort to validate all existing popular angular libraries here: https://github.com/mgechev/ngcc-validation. Where NGXS does seem to be included. Can't really find any confirmation that things are working, just absence of existing issues.

@Koslun I've pressed Ctrl + F and typed ngxsstore and it seems to be there. Or am I looking into a wrong way?

@C1E1S1T #1278

So, Angular 9 works for me, but not sure for lazy modules

Angular 9.0.0-next.4, does not work for lazy modules.

@unlight Could you provide a reproduction repo or some screenshots? Would be great.

@arturovt

git clone https://github.com/unlight/rd-angular-starter
cd rd-angular-starter
git checkout origin/ngxs-router
npm install
npm run dev
// start http://localhost:4200/
// Can't resolve all parameters for RouterState: (?, ?, ?, ?, ?, ?, ?).

image

Looks like for non-lazy it doesn't work too for me

I've added a comment in the Angular's repo issue.

Which repo? I could not find it. Could you provide link to this comment?

Which repo? I could not find it. Could you provide link to this comment?

#1165 (comment)

It's been fixed by the Angular team.

It's been fixed by the Angular team.

Not yet, we're waiting for the next version and probably NGXS+Ivy will be compatible starting from version 9.

I see. I thought they fixed it here angular/angular#31791

I see. I thought fixed it here angular/angular#31791

We haven't checked yet as the new compiler version hasn't been published. Looking forward to the next version, prolly 9.0.0-next.7. But still we need a stable 9 version release โšก

9.0.0-next.7 released

Gentlemen, tested with 9.0.0-next.7 and it works:

image

AOT works as well.

cc @ngxs/core

Not working with ng9-next7

Here is a toy project to reproduce the ngxs/ivy issue - dubzzz/todolist-front@da34247

@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.

Failed compilation when switching to target = es5

ERROR in ./node_modules/@ngxs/router-plugin/__ivy_ngcc__/fesm5/ngxs-router-plugin.js 650:76-100
"export 'NgxsFeatureModule' (imported as 'ษตngcc1') was not found in '@ngxs/store'

But ok for es2015.

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.

@mgechev it is bug Angular CLI?

@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.

Here's a PR that should fix the export 'NgxsFeatureModule' (imported as 'ษตngcc1') was not found in '@ngxs/store' issue: angular/angular#32902

I can confirm by adding @Injectable() before @State(...) it's working with angular 9 rc0

Error occurs on version 9.0.0-rc.2:

Error: Can't resolve all parameters for AuthState: (?)
...
AuthState --> constructor(public store: Store)

@Newbie012 try last Angular 9-rc.5 + ngxs/store@dev

But we have problem with integration test

image

@splincode can you provide a minimal demo where we can reproduce the problem?

Worked with Angular 9-rc.7

Hi all! I'm not sure that is the same problem or just my stupid mistake. I have the problem when try to use di in state like I use it before.

Error: Can't resolve all parameters for TestState: (?).

This repo can reproduce the issue, only thing I did after ng new, is add @ngxs/store@dev and change files inside /src/app.
https://github.com/freemanlam/ng9-ngxs-di-issue

https://www.ngxs.io/advanced/ivy-migration-guide

https://github.com/freemanlam/ng9-ngxs-di-issue/blob/master/src/app/test.state.ts

Works

@State<TestStateModel>({
  name: 'test',
  defaults: {
    oh: '123'
  }
})
@Injectable()
export class TestState {

  constructor(
    private testService: testService
  ) {
    debugger;
    testService.test();
  }

}

https://www.ngxs.io/advanced/ivy-migration-guide

https://github.com/freemanlam/ng9-ngxs-di-issue/blob/master/src/app/test.state.ts

Works

@State<TestStateModel>({
  name: 'test',
  defaults: {
    oh: '123'
  }
})
@Injectable()
export class TestState {

  constructor(
    private testService: testService
  ) {
    debugger;
    testService.test();
  }

}

Awesome, I really forgot this change in ng9, thanks :P