vuex-module-decorators: Namespaces do not function. Throws "ERR_ACTION_ACCESS_UNDEFINED" when using namespaces
I setup namespaces for my Vuex modules, and after that the following error is thrown whenever I try and access an action:
ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access this.someMutation() or this.someGetter inside an @Action? That works only in dynamic modules.
Vuex Module:
@Module({ namespaced: true, name: 'Accounts' })
export default class AccountStore extends VuexModule {
accounts: AccountModel[] = [];
@Mutation
SetAccounts(accounts: AccountModel[]){
this.accounts = accounts;
}
@Action({commit: 'SetAccounts'})
FetchAll(){
axios.get('/api/accounts').then((response) => {
return response.data;
})
}
}
Store initialization:
Vue.use(Vuex);
export default new Vuex.Store({
state:{},
modules:{
Accounts: AccountStore
}
})
Calling It:
this.$store.dispatch('Accounts/FetchAll');
If I remove the namespace bits and call this.$store.dispatch(FetchAll');
it works as expected.
I assume this is a problem with my usage of this?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 19 (1 by maintainers)
@Action({ rawError: true })
You can add this to the decorator. I think the decorator catches every error that happens inside the action and just give you this error. I had the same thing.Edit: turns out there was a problem with my main component class and after I fixed it, the problem went away.
I’m getting this same error when trying to namespace modules. Without namespacing everything works fine.
My super simple store:
If I add
rawError: true
I get: “Unhandled promise rejection 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)””Using Vue 2.6.6 and vuex 3.1.0
Changing from:
@Module({ namespaced: true, name: 'user', store })
To:
@Module({ namespaced: true, store })
As @fdeitelhoff mentioned omitting
name
seems to fix the problem for me as well. I have a super basic namespaced user module in the root store. That was throwing this error when trying to dispatch an action.I think something somewhere is a red herring here. I, too, had this problem, though it didn’t seem related to namespaces. I was going to file an issue about creating promises in actions causing errors, because whenever I created a promise, my actions failed with this same error.
Turns out adding
({rawError: true})
revealed exactly what my error was. It had nothing to do with promises.So I think there needs to be better error-reporting in this particular failure case, since any errors are getting caught and reported with this generic message. I lost a few hours to this. 😃
Thanks.
Did anyone manage to solve this problem? As others in this thread, I get the error following error
ERR_ACTION_ACCESS_UNDEFINED
withrawError: false
andERR_STORE_NOT_PROVIDED
withrawError: true
if I try to call a namespaced action.If I use the
getModule
function before calling the action, the error does not occur.So this is an fix to the problem, but I wouldn’t say it’s an optimal solution. This really seems like a bug to me.
if there is an reject in a Promise it always fail without rawError, I think this case should be in the read-me, is a common case.
@douglasg14b You don’t return the promise in your
FetchAll
@Action
. Sovuex-module-decorators
will only receiveundefined
. Did you check if this causes your issue?Removing the module name in the module declaration fixes it for me! Not quite sure if there will be other errors when the module name is missing. But for the moment everything seems to be okay!
@sfakir Have you tried taking the name property out of the Module annotation?
To avoid using
getModule()
before calling every action, you can export your Vuex module like this:You might have to also use the param
dynamic: true
in your@Module
decorator, I am not sure.