ОШИБКА во время компиляции шаблона AppModule - PullRequest
0 голосов
/ 26 июня 2018

Попытка создать приложение Angular 6.Я получаю следующую ошибку при использовании --prod

ERROR in Error during template compile of 'AppModule'
  Expression form not supported in 'reducers'
    'reducers' contains the error at app/app.module.ts(48,3).

app.module.ts

  import AuthEffects from './store/auth/auth.effects';
    import ContentEffects from './store/content/content.effects';
    import NavigationEffects from './store/navigation/navigation.effects';
    import ConfigEffects from './store/config/config.effects';

    import { ICommonAppState } from './app.state';
    import { reducer as authReducer, key as authKey } from './store/auth';
    import { reducer as configReducer, key as configKey } from './store/config';
    import { reducer as contentReducer, key as contentKey } from './store/content';
    import { reducer as navigationReducer, key as navigationKey } from './store/navigation';

    import { PageContainerComponent } from './page-container/page-container.component';
    import { BenefitsComponent } from './+benefits/benefits.component';
    import { NavigationComponent } from './navigation/navigation.component';

    const enhancers = [];
    if (!environment.production) {
      enhancers.push(StoreDevtoolsModule.instrument({ maxAge: 10 }));
    }

    export const reducers: ActionReducerMap<ICommonAppState> = {
      [authKey]: authReducer,
      [configKey]: configReducer,
      [navigationKey]: navigationReducer,
      [contentKey]: contentReducer,
    };

    const effects = [AuthEffects, ConfigEffects, NavigationEffects, ContentEffects];

    @NgModule({
      declarations: [AppComponent, NavigationComponent, PageContainerComponent, BenefitsComponent],
      imports: [
        BrowserModule,
        HttpClientModule,
        AppRoutingModule,
        SharedComponentsModule,
        StoreModule.forRoot(reducers),
        EffectsModule.forRoot(effects),
        ...enhancers,
      ],
      providers: [
        { provide: APP_BASE_HREF, useValue: '/content-manager/' },
        { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },
        DiscoveryService,
        AuthService,
        JWTService,
        ConfigService,
        ContentService,
        NavigationService,
        TenantGuard,
        AuthGuard,
      ],
      bootstrap: [AppComponent],
    })
    export class AppModule {}

Строка 48, где сообщается об ошибке,похоже, что

export const reducers: ActionReducerMap<ICommonAppState> = {
  [authKey]: authReducer,
  [configKey]: configReducer,
  [navigationKey]: navigationReducer,
  [contentKey]: contentReducer,
};

Я использую Angular 6 с NgRX 6. Я не могу понять, почему это не работает.Я следовал документации и моя сборка приложения просто прекрасна, если я не использую флаг prod.Однако сборка раздутая и медленная, я бы предпочел сборку AOT.

Ответы [ 2 ]

0 голосов
/ 28 октября 2018

Была такая же проблема ... попробуйте использовать токен инъекции для предоставления ActionReducerMap.

export const reducers: ActionReducerMap<ICommonAppState> = {
    [authKey]: authReducer,
    [configKey]: configReducer,
    [navigationKey]: navigationReducer,
    [contentKey]: contentReducer,
};
export const REDUCERS_TOKEN = new InjectionToken<ActionReducerMap<ICommonAppState>>('App Reducers');
export const reducerProvider = { provide: REDUCERS_TOKEN, useValue: reducers };

, а затем используйте его следующим образом

  imports: [
      ...
      StoreModule.forRoot(REDUCERS_TOKEN, { metaReducers }),
      ...
  ],
  providers: [reducerProvider]

И компилятор AOT долженнадеюсь, мы сможем статически анализировать код (не исключая его).

0 голосов
/ 28 сентября 2018

Я также столкнулся с той же ошибкой, и в моем случае это была просто опечатка в моем модуле.У меня была одна запятая "," в массиве провайдера модуля.Попробуйте удалить запятую после contentReducer из вашего кода.

...