Failed to install Vuex in Vue3

Viewed 6884

I want to install Vuex but I get an error.

// error
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: vuejs-v-3@0.1.0
npm ERR! Found: vue@3.1.2
npm ERR! node_modules/vue
npm ERR!   vue@"^3.1.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^2.0.0" from vuex@3.6.2
npm ERR! node_modules/vuex
npm ERR!   vuex@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/hap/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/hap/.npm/_logs/2021-06-24T06_46_36_463Z-debug.log
// package.json

    {
  "name": "vuejs-v-3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@apollo/client": "^3.3.20",
    "axios": "^0.21.1",
    "bootstrap": "^5.0.2",
    "core-js": "^3.6.5",
    "graphql": "^15.5.1",
    "vue": "^3.1.2",
    "vue-router": "^4.0.10"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.0.0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

5 Answers

As @Seegy said,

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

As of Feb 2022,

  • If you are using Vue 2, use the following to install Vuex 3
    • npm install vuex@3.4.0 --save
  • If you are using Vue 3, use the following to install Vuex 4
    • npm install vuex --save or npm install vuex@next --save

had the same error just try npm install vuex@next --save instead of npm install vuex --save and it will work

This works for me: npm install vuex@next --save --force.

I tried this before but it didn't work for me

npm install vuex --save

So, this worked for me:

npm install vuex@next --save
Related