Hi
I have is problem.
I run is command ng build --prod and I get is error message.
Thank you!
ERROR in libsfine-amountsrclibfine-amount.module.ts(20,89): Error during template compile of 'FineAmountModule'
Function calls are not supported in decorators but 'createEntityAdapter' was called in 'fineAmountInitialState'
'fineAmountInitialState' references 'adapter'
'adapter' calls 'createEntityAdapter' at libsfine-amountsrclib+statefine-amount.reducer.ts(19,60).
export const FINEAMOUNT_FEATURE_KEY = 'fineAmount';
export interface FineAmountState extends EntityState<FineAmountViewModel> {
selectedId?: string | number;
loaded: boolean;
loading: boolean;
error?: any;
isSave: boolean;
}
export const adapter: EntityAdapter<FineAmountViewModel> = createEntityAdapter<FineAmountViewModel>();
export const fineAmountInitialState: FineAmountState = adapter.getInitialState({
selectedId: null,
loaded: false,
loading: false,
error: null,
isSave: false
});
export interface FineAmountPartialState {
readonly [FINEAMOUNT_FEATURE_KEY]: FineAmountState;
}
export function fineAmountReducer(
state: FineAmountState = fineAmountInitialState,
action: FineAmountAction
): FineAmountState
@NgModule({
imports: [FineAmountRoutingModule
, CommonModule
, FormsModule
, ReactiveFormsModule
, StoreModule.forFeature(FINEAMOUNT_FEATURE_KEY, fineAmountReducer, { initialState: fineAmountInitialState })
, EffectsModule.forFeature([FineAmountEffects])
, SharedModule
],
declarations: [FineAmountsComponent, AddOrUpdateFineAmountDialogComponent, FineAmountDetailComponent],
providers: [FineAmountFacade],
entryComponents: [AddOrUpdateFineAmountDialogComponent]
})
export class FineAmountModule {}
md5-769ca98e19c45180d5ba8c4afcb7fa39
"dependencies": {
"@angular/animations": "^6.1.9",
"@angular/cdk": "^6.4.7",
"@angular/common": "^6.1.9",
"@angular/compiler": "^6.1.9",
"@angular/core": "^6.1.9",
"@angular/forms": "^6.1.9",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.9",
"@angular/platform-browser-dynamic": "^6.1.9",
"@angular/router": "^6.1.9",
"@mdi/font": "^2.8.94",
"@ngrx/effects": "6.0.1",
"@ngrx/entity": "^6.1.0",
"@ngrx/router-store": "6.0.1",
"@ngrx/store": "6.0.1",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"@nrwl/nx": "6.4.0",
"core-js": "^2.5.7",
"ng-zorro-antd": "^1.6.0",
"rxjs": "^6.3.3",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "^6.2.4",
"@angular/compiler-cli": "^6.1.9",
"@angular/language-service": "^6.1.9",
"@angular-devkit/build-angular": "~0.8.4",
"@ngrx/store-devtools": "^6.1.0",
"ngrx-store-freeze": "0.2.4",
"@nrwl/schematics": "6.4.0",
"jasmine-marbles": "0.4.0",
"@types/jasmine": "~2.8.9",
"@types/jasminewd2": "~2.0.5",
"@types/node": "~10.11.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~3.2.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.4",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.3.1",
"protractor": "~5.4.1",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"typescript": "~2.7.2",
"prettier": "1.14.3"
}
You don't need the initialState set in the forFeature config if you already have it set in the reducer function. Further support issues should be asked in the gitter channel
For those using the Nx ngrx schematic to add state, as Brandon mentions, you'll have to remove the
{ initialState: coursesInitialState } from the boilerplate that they set up. In my case I made a store called Courses, but yours may be different:
StoreModule.forFeature(COURSES_FEATURE_KEY, coursesReducer, {
initialState: coursesInitialState
})
should be:
StoreModule.forFeature(COURSES_FEATURE_KEY, coursesReducer)
I'm running into the same problem with maybe a slightly different issue. I have a reducer that is basically the same across all of my different modules, so I tried to abstract it by creating a function that returns the reducer function. It works fine if I do an ng build without the --prod flag. The issue occurs only when I try a prod build.
My NgModule:
@NgModule({
providers: [ ],
declarations: [],
imports: [
CommonModule,
RoutingModule,
SharedModule,
StoreModule.forFeature('feature', reducers),
EffectsModule.forFeature([ FeatureEffects, CollectionEffects ])
]
})
export class MyModule { }
Module Reducer:
export interface State extends EntityState<Feature> {
selectedId: string | null;
feature: Feature[] | null;
}
export const adapter: EntityAdapter<Feature> = createEntityAdapter<Feature>({
selectId: (feature: Feature) => feature.id,
sortComparer: false
});
export const initialState: State = adapter.getInitialState({
selectedId: null,
feature: null
});
export const reducer = entityReducerFactory(initialState, ActionTypes, adapter);
export const getSelectedId = (state: State) => state.featureId;
export const getFeature = (state: State) => state.feature
And my factory:
export function entityReducerFactory(initialState, actionTypes, adapter) {
return (state = initialState, action: any) => {
switch (action.type) {
case (actionTypes.LoadSuccess): {
return adapter.addMany(action.payload, state);
}
case actionTypes.CreateSuccess:
return adapter.addOne(action.payload, state);
case actionTypes.UpdateSuccess:
return adapter.updateOne(action.payload, state);
case actionTypes.UpdateManySuccess:
return adapter.updateMany(action.payload, state);
case actionTypes.DeleteManySuccess:
return adapter.removeMany(action.payload, state);
default: {
return state;
}
}
};
}
Most helpful comment
For those using the Nx ngrx schematic to add state, as Brandon mentions, you'll have to remove the
{ initialState: coursesInitialState }from the boilerplate that they set up. In my case I made a store called Courses, but yours may be different:should be: