Platform: with latest ngrx 4 getting AOT Error encountered resolving symbol values staticall

Created on 20 Jul 2017  路  4Comments  路  Source: ngrx/platform

JIT works fine.
in AOT I get:

chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in Error encountered resolving symbol values statically. Calling function 'UserModel', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol INITIAL_APP_DB in C:/msweb/studiolite/src/store/store.data.ts, resolving symbol INITIAL_APPLICATION_STATE in C:/msweb/studiolite/src/store/application.state.ts, resolving symbol AppModule in C:/msweb/studiolite/src/app/app-module.ts, resolving symbol AppModule in C:/msweb/studiolite/src/app/app-module.ts, resolving symbol AppModule in C:/msweb/studiolite/src/app/app-module.ts
webpack: Failed to compile.
webpack: Compiling..

And I don't run and static on UserModel, not sure where to look next? Is it a bug in latest release? is it me?

this is the repo:
https://github.com/born2net/studio-lite/tree/ng43

and these are the store files:
https://github.com/born2net/studio-lite/tree/ng43/src/store

and this is UserModel class, which I have no idea why its complaining on it needing to be Lambada, FYI going back to ngrx 2 all is well:
https://github.com/born2net/studio-lite/blob/ng43/src/models/UserModel.ts

@angular/cli: 1.2.1
node: 6.9.5
os: win32 x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.1
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1
@ngtools/webpack: 1.5.1

anything you recommend I look at?

tx

Sean

Most helpful comment

Initial state is described here. As such if you want AoT compilation, you'll need all of your symbols to resolve statically. In your case, UserModel is being instantiated as initial state in store.data.ts.

The solution then is to provide a function as your initial state. So in application.state.ts:

export const INITIAL_APPLICATION_STATE: ApplicationState = {
    msDatabase: INITIAL_STORE_DATA,
    appDb: INITIAL_APP_DB
};

export function getInitialState() {
  return INITIAL_APPLICATION_STATE;
}

In app-module.ts:

// Line 27
import {getInitialState} from "../store/application.state";

// Line 127
StoreModule.forRoot(reducers, {
  initialState: getInitialState
}),

With this the app compiles using x_prod_aot npm script.

All 4 comments

Initial state is described here. As such if you want AoT compilation, you'll need all of your symbols to resolve statically. In your case, UserModel is being instantiated as initial state in store.data.ts.

The solution then is to provide a function as your initial state. So in application.state.ts:

export const INITIAL_APPLICATION_STATE: ApplicationState = {
    msDatabase: INITIAL_STORE_DATA,
    appDb: INITIAL_APP_DB
};

export function getInitialState() {
  return INITIAL_APPLICATION_STATE;
}

In app-module.ts:

// Line 27
import {getInitialState} from "../store/application.state";

// Line 127
StoreModule.forRoot(reducers, {
  initialState: getInitialState
}),

With this the app compiles using x_prod_aot npm script.

tx so much will try it first thing tomorrow morning

Thanks sooooo much, did the trick!

Thank you! was looking all over for that

Was this page helpful?
0 / 5 - 0 ratings