question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngrx 4 + prod flag

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

4reactions
maxisamcommented, 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?

2reactions
dojchekcommented, Jul 28, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

reducers are not called when using --prod flag #147 - GitHub
hello :) I try to migrate my ngrx store to v4 and I have an issue when using the --prod flag with ng...
Read more >
How to write ngrx effects and reducers so that I can have ...
I am working on an Angular application using @ngrx/store and @ngrx/effects. The blogs I have been through all use flags like loading, ...
Read more >
Angular state management made simple with NgRx
The NgRx Store is a Redux-inspired state management system that enables you to ... The -g flag will ensure that the Angular CLI...
Read more >
Angular: NGRX a clean and clear introduction - Level Up Coding
The objective of this article is to provide a clean and clear introduction to ngrx. In order to accomplish this, I am going...
Read more >
Chapter 15. Maintaining app state with ngrx - liveBook · Manning
A brief introduction to the Redux data flow; Maintaining your app state using the ngrx library; Exploring another implementation of the Mediator design ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found