question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error "[vuex] unknown action type:" in Nuxt, however I did all exactly according "Accessing modules with NuxtJS" documentation

See original GitHub issue

Let me repeat: I did all according Accessing modules with NuxtJS explanations.

Store Module:

import { Action, Mutation, VuexModule, Module } from 'vuex-module-decorators';


@Module({
  stateFactory: true,
  name: "AUTHENTICATION__STORE_MODULE"
})
export default class AuthenticationStoreModule extends VuexModule {

  private _token: string | null = null;

  @Action
  public async signIn(formData: { userId: string, password: string }): Promise<void> {
    console.log("Called!");
    const token: string = await new Promise(
        (resolve: (token: string)=> void): void => {
          setTimeout(() => { resolve('mock-token'); }, 2000);
        });
    console.log(token);
  }

  // ...
}

TypeScript types validation is all right. However, await authenticationStoreModule.signIn(formData) does not work.

Component:

import { Vue, Component, Prop } from 'vue-property-decorator';
import VueReferencesInspector from '~/utils/VueReferencesInspector';

import { authenticationStoreModule } from "~/store/";

interface IElementUiForm extends Vue {
  validate: (validationResult: (valid: boolean)=> void)=> void;
}


@Component
export default class extends Vue {

  // ...

  private onSubmit(): void {

    // ...

      try {

        console.log('~~~');
        console.log(authenticationStoreModule);
        console.log(authenticationStoreModule.signIn(formData));

        await authenticationStoreModule.signIn(formData);
        this.$router.push('/admin');
      } catch (error) {
        this.dataIsBeingSubmittedNow = false;
      }
    });
  }
}

console.logs are;

image

As you see authenticationStoreModule and authenticationStoreModule.signIn are not undefined. However, console.log("Called!"); did not output, so action signIn has not been called.

📁Repro Project

Once npm install done,

  1. Execute npm run dev
  2. go to page http://localhost:3000/admin/login
  3. Try to login

You will see same console errors as in image.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

23reactions
woubuccommented, Feb 16, 2020

It took me some trial and error, and the documentation & examples don’t mention this at all, but it seems that you have to export default your module classes. See my minimal example that seems to work correctly.

20reactions
danielroecommented, Sep 22, 2019

Try:

@Module({
  name: 'auth',
  stateFactory: true,
  namespaced: true,
})

For Nuxt usage you should match the filename and namespace of your module, so this module should be in ~/store/auth.ts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuex, Nuxt: Unknown action type - Stack Overflow
When commiting/dispatching I constantly get error "unknown action/mutation type: name". Also my mutations and actions don't display in vue ...
Read more >
Vuex Unknown Action Type - ADocLib
[vuex] unknown action type: in Nuxt however I did all exactly according gives error: unknown mutation type: login I'm trying to split up...
Read more >
Creating Server-side Rendered Vue.js Apps Using Nuxt.js
In this article, Toptal Freelance Front-end Engineer Ben Jones introduces us to Nuxt.js, a server-side rendering library for Vue.js, inspired by the popular ......
Read more >
Unknown action type - nuxt - Vue Forum
I am trying to output a store action from my NUXT project, here is my action: export const actions = { async fetchTodos({...
Read more >
Store - Nuxt TypeScript
There are a number of different options for writing and accessing the store in a Nuxt project using TypeScript. Class-based. vuex-module-decorators.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found