Object(...) is not a function for Vuex Store
Asked Answered
I

2

6

I'm in Vue 3, I started with adding a new Vuex.Store to vue, but I continuously get this javascript error. I also tried the same thing with createStore since I use Vue 3, but it's still the same.

What am I missing?

const store = new Vuex.Store({
    modules: {
    account: {
    namespaced: true,
    state: () => ({  }), 
    getters: {
        isAdmin () {  } 
    },
    actions: {
        login () {  } 
    },
    mutations: {
        login () {  } 
    }
 }}
});  

Than I add to Vue as store:

new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app');

What am I missing?

Complete error

vuex.esm-browser.js?5502:644 Uncaught TypeError: Object(...) is not a function
at resetStoreState (vuex.esm-browser.js?5502:644)
at new Store (vuex.esm-browser.js?5502:387)
at createStore (vuex.esm-browser.js?5502:337)
at eval (main.js?56d7:37)
at Module../src/main.js (app.js:1105)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at Object.1 (app.js:1118)
at __webpack_require__ (app.js:849)
at checkDeferredModules (app.js:46)
Inheritrix answered 27/10, 2020 at 11:4 Comment(2)
Can you post the complete error with stack trace?Kerbing
I added the complete error.Inheritrix
B
10

If you are using Vue 3 you need to use Vuex 4.

import { createStore } from 'vuex'
import { createApp } from 'vue'

const store = createStore({
  state () {
    return {
      count: 1
    }
  }
})

const app = createApp({ /* your root component */ })
app.use(store)

https://vuex.vuejs.org/guide/#vuex-4-x-for-vue-3

Bent answered 27/10, 2020 at 11:13 Comment(1)
OK, I installed everything from stretch and worked as you said. But sadly, I had a problem with bootstrap with Vue 3, so I decided to continue with Vue 2.Inheritrix
N
4
npm uninstall vuex
npm install [email protected]
//  Convert version to 3.4.0 Can perfectly solve this problem 
Nougat answered 20/6, 2022 at 19:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.