ta539tg70
ta539tg70

Reputation: 307

Module not found: Error: Can't resolve 'vuex' in '/myapp/src/store'

I am new to Vue/Vuex.
I'm trying to make a login function in my Vue.js app, and I'm getting the error below even though I have installed Vuex in my project.

./src/store/index.js
Module not found: Error: Can't resolve 'vuex' in '/myapp/src/store'
// package.json

"dependencies": {
  "axios": "^0.19.2",
  "core-js": "^2.6.5",
  "vue": "^2.6.10",
  "vue-router": "^3.4.2",
  "vuex": "^3.5.1"
},
// src/store/index.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    userId: "",
    userToken: ""
  },
  mutations: {
    updateUser(state, user) {
      state.userId = user.userId;
      state.userToken = user.userToken;
    }
  },
  actions: {
    auth(context, user) {
      context.commit('updateUser', user);
    }
  },
  modules: {},
})

export default store

Any suggestions to solve this problem?

Upvotes: 4

Views: 22347

Answers (4)

Malki Mohamed
Malki Mohamed

Reputation: 1688

Each version of Vue uses a specific Vuex package.

  • Vue 3 uses Vuex 4
  • Vue 2 uses Vuex 3

Try this solution here Failed to install Vuex in Vue3

Upvotes: 0

Anisha Agarwal
Anisha Agarwal

Reputation: 56

I too was facing this error. These things worked for me:

  1. Restart your editor. (webstorm in my case) Sometimes it doesn't recognize the newly added files/folder (node modules)
  2. Delete node_modules and yarn.lock and install again.
  3. import Vuex from "vuex" or import Vuex from "Vuex".

Upvotes: 2

j harding
j harding

Reputation: 31

As of Jan 2021, there was a piece that I found that you had to enter @next in your terminal.

For example:

npm install --save vuex@next

Hope this helps.

Upvotes: 3

Mirko t.
Mirko t.

Reputation: 491

try running npm i maybe its not added yet

Also try this: import Vuex from 'Vuex' I think the import needs to be Uppercase.

Upvotes: 2

Related Questions