Reputation: 307
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
Reputation: 1688
Each version of Vue uses a specific Vuex package.
Try this solution here Failed to install Vuex in Vue3
Upvotes: 0
Reputation: 56
I too was facing this error. These things worked for me:
node_modules
and yarn.lock
and install again.Upvotes: 2
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
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