Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngrx 4 + prod flag #43

Closed
dojchek opened this issue Jul 24, 2017 · 7 comments
Closed

ngrx 4 + prod flag #43

dojchek opened this issue Jul 24, 2017 · 7 comments

Comments

@dojchek
Copy link

dojchek commented Jul 24, 2017

I was able to integrate localstorage and it works when running with ng serve'. However, running the ng build --prod` I get the following exception:

ERROR in Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler

The way I add a localstoragesync is (app.module.ts):

StoreModule.forRoot(reducers , {
       metaReducers: [
         localStorageSync({keys: ['filter', 'auth']})
       ]
     })

As soon as I remove metaReducers, it builds successfully

@dojchek
Copy link
Author

dojchek commented Jul 24, 2017

This is likely due to this issue:
link

@dojchek
Copy link
Author

dojchek commented Jul 24, 2017

I debugged a bit and seems like the issue is with arrow functions. Once I convert the localStorageSync like in the following GIST
it no longer throws error..

@kevfuzz
Copy link

kevfuzz commented Jul 26, 2017

Same issue. Any ETA on when this might be fixed?

@bradyshutt
Copy link

I can't even get ng serve to run without the "Error encountered resolving symbol values statically..." error, and a failed compilation.

After the failed compilation, triggering a re-compilation (ie, changing a file as ng serve watches for file changes) results in a successful compile. ng serve seems to only give this error on the initial compilation.

@maxisam
Copy link

maxisam commented Jul 27, 2017

@kevfuzz technically, this doesn't need to be fixed.

use this following way to wrap localStorageSync and put it into an array for metaReducers. You are good to go. (It works in AOT)

export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> {
  return localStorageSync({ keys: ['user'], rehydrate: true })(reducer);
}

@btroncone maybe we can put this in to the document?

@kevfuzz
Copy link

kevfuzz commented Jul 27, 2017

Perfect, thanks.

@dojchek
Copy link
Author

dojchek commented Jul 28, 2017

Nice! Thank you @maxisam
Closing this issue - It would definitely be useful to add this to docs for future reference

@dojchek dojchek closed this as completed Jul 28, 2017
saulshanabrook added a commit to saulshanabrook/ngrx-store-localstorage that referenced this issue Aug 10, 2017
btroncone pushed a commit that referenced this issue Aug 14, 2017
* Update readme for ngrx 4.0

For some reason, we need to manually specify the type of the meta-reducers, as shown in 
ngrx/platform#170 (comment)

Fixes #45

* Fix readme for ngrx store 4.0

uses fix from #43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants