8

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: [email protected]
npm ERR! Found: [email protected]
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 [email protected]
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"
  ]
}

4
  • how did you install it? which command did you use? Commented Jun 24, 2021 at 7:07
  • i'm using npm install vuex --save Commented Jun 24, 2021 at 8:00
  • 4
    try out npm install vuex@next --save Commented Jun 24, 2021 at 8:01
  • now, solved. Apparently, I'm using node v16+ . that v16 node doesn't work for vuex. to fix it i used node v14 Commented Jun 24, 2021 at 8:04

5 Answers 5

13

When using Vue3, refer to Vuex 4 Documentation to install Vuex 4 with

npm install vuex@next --save

and when using Vue2, refer to Vuex 3 Documentation to install Vuex 3 with

npm install vuex --save

Sign up to request clarification or add additional context in comments.

Comments

6

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
  • If you are using Vue 3, use the following to install Vuex 4
    • npm install vuex --save or npm install vuex@next --save

Comments

4

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

Comments

1

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

1 Comment

According to the npm install docs (might need to search the text for --force to find it though): "The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk". So I guess this might help in case a local copy exists but is corrupted.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.