Search code examples
angularngrx

Ngrx TypeError: can't convert undefined to object


I get this error message when I build my angular 8.0.1 application. My environment is as follows (Ubuntu 18):

  • Angular 8.0.1
  • Rxjs 6.5.0
  • Ngrx Core 1.2.0
  • Ngrx Store 8.0.1

I am building the project as follows: 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
};

This code is from my auth angular library


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);
}

This is the trace from the console:

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

I must say am not an expert in Ngrx or Angular, so I assume I am doing something wrong. Any help will be sincerely appreciated


Solution

  • Regarding dependencies you mentioned, you should have at least one problem with @ngrx/core.

    It's an old package from previous ngrx versions. You have to remove it.