AOT: Calling function 'StoreModule' not supported with plain function reducer
BrainCrumbz opened this issue · 2 comments
Hello all
We're hitting the following issue when we add @ngrx/store to a project built in AOT-mode through ngtools/webpack:
as soon as we add a plain (dummy) function reducer to the imports
list with StoreModule.provideStore(appReducer)
the AOT build breaks on that line. The same project is built in AOT successfully when not importing StoreModule.provideStore(...)
.
We did search through similar issues, both open and closed, both here and on angular-cli repo, but none of those seem to fit. Many are related to using combineReducer
, or exporting a const
instead of a function
. But our dummy scenario seems even more basic than that:
// app/reducer.ts
export interface AppState {
}
export function appReducer(state: AppState, action: Action): AppState {
return state;
}
// app/module.ts
import { StoreModule } from '@ngrx/store';
// ...
import { appReducer } from './reducer';
@NgModule({
// ...
StoreModule.provideStore(appReducer),
// ...
})
// ...
Here are the actual repro steps with a sample project:
Dependencies
- "@angular/***": "4.1.3",
- "@ngtools/ webpack": "1.3.3", (blank only added here, for markdown issue)
- "@ngrx/core": "1.2.0",
- "@ngrx/store": "2.2.2",
- "webpack": "2.5.1",
- "typescript": "2.3.2",
Environment
- Windows 10 64 bit
- npm --version: 3.9.5
Steps to reproduce
- Clone sample project branch https://github.com/BrainCrumbz/ngtools-webpack-demo/tree/issue/StoreModule-call-not-supported
npm install
npm run build-prod
Expected:
- Build completes fine
Actual:
- Build fails with message (excerpt):
[393] ./~/zone.js/dist/zone.min.js 29.8 kB {1} [built]
[] -> factory:2792ms building:2485ms dependencies:748ms = 6025ms
+ 383 hidden modulesERROR in Error encountered resolving symbol values statically. Calling function 'StoreModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in d:/ngtools-webpack-demo/src/app/module.ts, resolving symbol AppModule in d:/ngtools-webpack-demo/src/app/module.ts
Child src\shared\view\not-found.component.html:
[0] ./src/shared/view/not-found.component.html 376 bytes {0} [built]
factory:140ms building:28ms = 168ms
The message relates to typical issue with AOT and usage of lambda or explicit function calls. But this is not our case, apparently. Or if it is, then it should happen for any project with AOT and ngrx/store.
What are we doing wrong?
Hi there. Can anyone confirm this problem as well?
Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks!