Vuex-module-decorators: NuxtJs ERR_STORE_NOT_PROVIDED

Created on 4 Jan 2020  路  2Comments  路  Source: championswimmer/vuex-module-decorators

I create Module in index.ts

import { Store, ActionTree } from 'vuex';
import { getModule } from 'vuex-module-decorators';
import cartModule from '~/store/cart/index';

let cartStore: cartModule;

const initializer = (store: Store<any>): void => {
    cartStore = getModule(cartModule, store);
};

export const plugins = [initializer];

export {
    cartStore,
}

but when I try call to action in Component

import { cartStore } from '~/store';
@Component
...
onClick(): void {
        cartStore.add_item({}).then(() => {});
}

I have error

Uncaught (in promise) Error: ERR_STORE_NOT_PROVIDED: To use getModule(), either the module should be decorated with store in decorator, i.e. @Module({store: store}) or store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)

but if I add in the component

import { cartStore } from '~/store';
import { getModule } from 'vuex-module-decorators';
import cartModule from '~/store/cart/index';
@Component
...
onClick(): void {
        cartStore.add_item({}).then(() => {});
}
protected created() {
        getModule(cartModule, this.$store);
}

It's work... why, why it's happened?

Most helpful comment

Same issue here. I did what documenation says:

cartStore = getModule(cartModule, store);

But still getting ERR_STORE_NOT_PROVIDED error. Any suggestion? Is it a bug in vuex-module-decorators?

All 2 comments

Same issue here. I did what documenation says:

cartStore = getModule(cartModule, store);

But still getting ERR_STORE_NOT_PROVIDED error. Any suggestion? Is it a bug in vuex-module-decorators?

Same issue here as well #244. I guess it's not suitable yet for production.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darthf1 picture darthf1  路  5Comments

tuvokki picture tuvokki  路  7Comments

blainehansen picture blainehansen  路  4Comments

cyberflohr picture cyberflohr  路  4Comments

souphuhn picture souphuhn  路  5Comments