Vuex: Watching vuex getters is causing: [vuex] module namespace not found in mapGetters() error

Created on 30 Sep 2019  路  4Comments  路  Source: vuejs/vuex

Version

3.1.1

Reproduction link

https://codesandbox.io/s/vue-template-bms46

Steps to reproduce

Just go to the "Link to minimal reproduction" and focus on App.vue where I have:

  computed: {
    ...mapGetters("module", {
      user: "person"
    })
  },

  watch: {
    user: {
      handler(user) {
        console.log(user);
      },
      deep: true
    }
  },

What is expected?

Having the computed and watcher properties should work fine..

What is actually happening?

However, the watcher seems to cause an issue and the user getter becomes undefined and in the console you see the error:

[vuex] module namespace not found in mapGetters()

If you remove the user watcher everything works normally.


How can the watcher affect the mapGetter ???

Most helpful comment

You should register the module in beforeCreate hook as created hook is triggered after computed properties are initialized.

All 4 comments

@changavila the problem is that I am using namespaced modules.

You should register the module in beforeCreate hook as created hook is triggered after computed properties are initialized.

@changavila the problem is that I am using namespaced modules.

Oh, right, Sorry.

Was this page helpful?
0 / 5 - 0 ratings