TypeError: невозможно прочитать свойство 'release' undefined в магазине ngrx с angular только в производственной сборке

У меня возникла проблема, но только после производственной сборки во время выполнения. Теперь я не уверен, ошибка ли это или я делаю ошибку. Я получаю сообщение об ошибке «TypeError: Cannot read property 'release' of undefined». " в консоли (браузере), если я загружу следующий функциональный модуль с помощью ngrx (во время выполнения):

    import { AccountDto } from '../../../dto';
import * as fromAccountActions from '../actions/account.actions';

export interface AccountState {
  loading: boolean;
  loaded: boolean;
accountItems: AccountDto[];
}

export const initialState: AccountState = {
  loading: false,
  loaded: false,
  accountItems: []
};


export function accountReducer(
  state = initialState,
  action: fromAccountActions.AccountActions
): AccountState {

  switch (action.type) {
    case fromAccountActions.LOAD_ACCOUNT: {
      // console.log(action.type);
      return { ...state, loading: true };
    }

    case fromAccountActions.LOAD_ACCOUNT_FINISHED: {
      console.log('Finished: ' + action.payload);
      return {
        ...state,
        loading: false,
        loaded: true,
        accountItems: action.payload
      };
    }

    case fromAccountActions.LOAD_ACCOUNT_FAILED: {
      return {
        ...state,
        loading: false,
        loaded: false,
        accountItems: []
      };
    }

    default:
      return state;
  }
}

export const getAccountItems = (state: AccountState) => state.accountItems;
export const getAccountLoading = (state: AccountState) => state.loading;
export const getAccountLoaded = (state: AccountState) => state.loaded;

index.ts в редукторах

import * as fromReducer from './account.reducers';
import { ActionReducerMap } from '@ngrx/store';
import { createFeatureSelector } from '@ngrx/store';

export interface AccountState {
  account: fromReducer.AccountState;
}

export const reducers: ActionReducerMap<AccountState> = {
  account: fromReducer.accountReducer
};

export const getAccountState = createFeatureSelector<AccountState>('account');

account.selectors.ts

import { createSelector } from '@ngrx/store';
import * as fromReducer from '../reducers/account.reducers';
import * as fromFeature from '../reducers';

export const getCompleteAccountState = createSelector(
  fromFeature.getAccountState,
  (state: fromFeature.AccountState) => state.account
);
export const getAccountLoading = createSelector(
  this.getCompleteAccountState,
  fromReducer.getAccountLoading
);
export const getAccountLoaded = createSelector(
  this.getCompleteAccountState,
  fromReducer.getAccountLoaded
);
export const getAllAccountItems = createSelector(
  this.getCompleteAccountState,
  fromReducer.getAccountItems
);

account.module.ts

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';

import { ThirdPartyModule } from '../thirdParty/thirdParty.module';
import { SharedModule } from './../shared/shared.module';
import { AccountListComponent } from './account-list/account-list.component';
import { AccountRoutesModule } from './account.routes';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { reducers, AccountEffects } from 'app/+account/store';

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    SharedModule,
    AccountRoutesModule,
    ThirdPartyModule,
    TranslateModule,
    StoreModule.forFeature('account', reducers),
    EffectsModule.forFeature([AccountEffects])
  ],

  declarations: [AccountListComponent],
  providers: [],
  exports: []
})
export class AccountModule {}

Помощь будет очень признательна. Спасибо


person FabianGosebrink    schedule 16.01.2018    source источник
comment
где используется свойство release, я не могу найти их в коде   -  person Aravind    schedule 16.01.2018
comment
Я тоже, это что-то изнутри angular или ngrx. Вот почему это происходит только в производственной среде, если я это сделаю ... --prod в angular CLI   -  person FabianGosebrink    schedule 16.01.2018
comment
Он проверит свойства времени выполнения, выполняя производственную сборку.   -  person Aravind    schedule 16.01.2018
comment
Значит, это проблема со свойством времени выполнения?   -  person FabianGosebrink    schedule 16.01.2018
comment
Взгляните на свою консоль (ng serve). Если у вас есть предупреждение (я) о некоторых циклических зависимостях в ваших селекторах, оно исходит оттуда.   -  person maxime1992    schedule 20.09.2018
comment
@FabianGosebrink Недавно я столкнулся с этой проблемой и исправил ее importing редуктором из файла редуктора вместо файла ствола   -  person Aravind    schedule 30.01.2020
comment
@ maxime1992 прямой импорт из файла редуктора import * as fromAccount from {app/+account/store/account.store должен разрешить циклические зависимости   -  person Aravind    schedule 30.01.2020


Ответы (2)


Я получил ту же ошибку при использовании NgRx, когда я импортировал файлы из файлов ствола.

Когда вы находитесь внутри функции состояния, если вы находитесь в файле, который импортирует один из экспортов из файла ствола index.ts, вы можете получить эту ошибку. Вы должны импортировать из относительного пути при импорте внутри папки функций. Только файлы вне папки функций должны использовать файл ствола для импорта вещей.

Я не выполнял импорт явно. Моя IDE сделала это автоматически. На то, чтобы разобраться, потребовалось полдня.

person frosty    schedule 09.07.2020

Я понял. В этом случае утверждение «это» неверно.

import { createSelector } from '@ngrx/store';
import * as fromReducer from '../reducers/account.reducers';
import * as fromFeature from '../reducers';

export const getCompleteAccountState = createSelector(
  fromFeature.getAccountState,
  (state: fromFeature.AccountState) => state.account
);
export const getAccountLoading = createSelector(
  getCompleteAccountState,
  fromReducer.getAccountLoading
);
export const getAccountLoaded = createSelector(
  getCompleteAccountState,
  fromReducer.getAccountLoaded
);
export const getAllAccountItems = createSelector(
  getCompleteAccountState,
  fromReducer.getAccountItems
)

работает. Спасибо всем.

Ваше здоровье

person FabianGosebrink    schedule 17.01.2018