V2 State Configuration Problem

Hi,

I am trying to configure state in my app. Following the docs almost exactly results in the following error after building:

Uncaught TypeError: e.map is not a function

This is using the latest beta 13 version

This is my main.ts where I register state:

import Aurelia from 'aurelia';
import { StateDefaultConfiguration } from '@aurelia/state';
import { DialogDefaultConfiguration } from '@aurelia/dialog';

import {initialState} from "./state/initialstate";
import {movieHandler} from "./state/action-handlers";

import { App } from './app';
import * as Components from './components';

Aurelia
    .register(DialogDefaultConfiguration)
    .register(
        StateDefaultConfiguration.init(
            initialState,
            movieHandler
        )
    )
    .register(Components)
    .app(App)
    .start();

In the docs is says I should have the movieHandler in an Array like this:

        StateDefaultConfiguration.init(
            initialState,
            [movieHandler]
        )

but that does not compile. Results in an " No overload matches this call" error. My IDE also highlights it as an error, removing the brackets compiles ok, but gives the the runtime error e.map is not a function.

This is my handler, almost identical to the docs version:

export function movieHandler(currentState, action) {
    return action.type === 'openMovie' ? { ...currentState, currentMovie: action.value } : currentState;
}

Any help would be appreciated. Thanks in advance.

edit: I need to be more specific. Everything is working when I am running the app in “debug” mode, with the start script. Its builds without error, but when trying to run in the browser the app crashes with the error above. When I remove the state configuration, everything works again.

1 Like

There doesn’t seem to be anything that could make a prod build different with a dev build for the state plugin, it seems weird you are having this issue. Is this a duplicate dependency issue, just double checking since you are sometimes getting build errors.

I could not create a simple example showing the problem. It might have just been a version mismatch. Aurelia was set to “latest” and state was set to beta v13. When I set everything to v13, deleted my node_modules and reinstalled all the npm packages everything worked as expected.

Sorry for the false alarm.