Ngrx TypeError:无法将未定义转换为对象

时间:2019-07-02 08:05:09

标签: angular ngrx

构建我的angular 8.0.1应用程序时收到此错误消息。 我的环境如下(Ubuntu 18):

  • 角度8.0.1
  • Rxjs 6.5.0
  • Ngrx Core 1.2.0
  • Ngrx Store 8.0.1

我正在按以下方式构建项目: ng build --base-href /dist/checks-gis-ng/ --prod --named-chunks true --output-hashing none --aot true --build-optimizer true

StoreModule.forRoot(appReducers),
    EffectsModule.forRoot(mainEffects),

export interface AppState {
    authState: AuthState,
    routerReducer: fromNgrxRouter.RouterReducerState<routeReducer.RouterStateUrl>;
}

export const appReducers: ActionReducerMap<AppState> = {
    authState: authReducer,
    routerReducer: fromNgrxRouter.routerReducer
};

此代码来自我的身份验证角度库


export interface AuthModuleState {
    authState: AuthState;
}

export interface AuthState extends AbstractData {
    isLoggedIn: boolean
    userData: UserData,
    message: String
}

export const initialAuthState: AuthState = {
    isLoggedIn : false,
    userData : new UserData(),
    message: ''
};

export const reducers: ActionReducerMap<AuthModuleState> = {
    authState: fromAuthReducer.authReducer,
};

const reducer = createReducer(
    initialAuthState,
    on(authActions.loginRequest, (state, { data }) => authReducerFunctions.onLoginRequestEvent(state, data)),
    on(authActions.loginRequestSuccess, (state, { data }) => authReducerFunctions.onLoginRequestSuccessEvent(state, data)),
    on(authActions.loginRequestError, (state, { data }) => authReducerFunctions.onLoginRequestErrorEvent(state, data)),
    on(authActions.logoutRequest, (state, { data }) => authReducerFunctions.onLogoutRequestEvent(state, data)),
    on(authActions.logoutRequestSuccess, (state, { data }) => authReducerFunctions.onLogoutRequestSuccessEvent(state, data)),
    on(authActions.logoutRequestError, (state, { data }) => authReducerFunctions.onLogoutRequestError(state, data)),
    on(authActions.signupRequest, (state, { data }) => authReducerFunctions.onSignupRequestEvent(state, data)),
    on(authActions.signupRequestSuccess, (state, { data }) => authReducerFunctions.onSignupRequestSuccessEvent(state, data)),
    on(authActions.signupRequestError, (state, { data }) => authReducerFunctions.onSignupRequestError(state, data))
);

export function authReducer(state: AuthState | undefined, action: Action) {
    return reducer(state, action);
}

这是来自控制台的跟踪:

TypeError: can't convert undefined to object main-es2015.f60865f5f16cd035360b.js:1:1223802
nx http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
rx http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
e http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
reduce self-hosted:354
addFeatures http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
Ox http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
n http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
Si http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
qi http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
qi http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
$i http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
create http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1
bootstrapModuleFactory http://localhost/dist/checks-gis-ng/main-es2015.f60865f5f16cd035360b.js:1TypeError: can't convert undefined to object main-es2015.f60865f5f16cd035360b.js:1:1223802

我必须说不是Ngrx或Angular的专家,所以我认为我做错了事。衷心感谢

1 个答案:

答案 0 :(得分:0)

关于您提到的依赖关系,ngrx应该至少有一个问题。

这是以前export class Color { static RED = 0; static BLUE = 1; static GREEN = 2; } let x = ['warning', 'info', 'success']; let anotherVariable = x[Color.RED]; <---- Error: Type 'Color' cannot be used as an index type. 版的旧软件包。 您必须将其删除。