Platform: Effects in Angular library not receiving injected actions on prod build (aot=true)

Created on 27 Dec 2018  Â·  5Comments  Â·  Source: ngrx/platform

Minimal reproduction of the bug/regression with instructions:

Clone https://github.com/l3ender/ngrx-aot. Running app without AOT works (npm run start). Running with AOT (npm run start:prod) causes bootstrap to fail. It appears that items (action and service) are not injected into the Effect.

Firefox error:

TypeError: this.actions$ is undefined

Chrome error:

Uncaught TypeError: Cannot read property 'pipe' of undefined

Expected behavior:

App behavior would be the same with or without AOT.

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

   "@angular/core": "^7.1.3",
    "@ngrx/effects": "^7.0.0",
    "@ngrx/store": "^7.0.0",

Using same version of Angular CLI (7.1.3).

$ ng v

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.1.4
Node: 10.13.0
OS: win32 x64
Angular: 7.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.11.4
@angular-devkit/build-angular      0.11.4
@angular-devkit/build-ng-packagr   0.11.4
@angular-devkit/build-optimizer    0.11.4
@angular-devkit/build-webpack      0.11.4
@angular-devkit/core               7.1.4
@angular-devkit/schematics         7.1.4
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.1.4
@schematics/angular                7.1.4
@schematics/update                 0.11.4
ng-packagr                         4.4.5
rxjs                               6.3.3
typescript                         3.1.6
webpack                            4.23.1

I would be willing to submit a PR to fix this issue

I'm not sure where I'd begin.

[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ x ] No

Most helpful comment

Yes I did.
I had index.ts which was exporting Effects from effects.ts file. And then used that export as import in Effects.forFeature
After changing to direct import without index.ts it worked.

All 5 comments

The problem was caused by a barrel import, https://github.com/l3ender/ngrx-aot/pull/1 contains a fix.

This problem occurs in my project.
I tried updating project to angular 8 and ngrx to 8 but it didn't help, it is the same, actions are not injected in service
Any advice?

@aleksandar-petrovic Having the same problem here, did you manage to get it working?

Yes I did.
I had index.ts which was exporting Effects from effects.ts file. And then used that export as import in Effects.forFeature
After changing to direct import without index.ts it worked.

@aleksandar-petrovic Thanks! That fixed it for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmytro-gokun picture dmytro-gokun  Â·  3Comments

axmad22 picture axmad22  Â·  3Comments

shyamal890 picture shyamal890  Â·  3Comments

hccampos picture hccampos  Â·  3Comments

NathanWalker picture NathanWalker  Â·  3Comments