为什么安装vuex会报错?

Why is there an error when installing vuex?

告诉我,我知道版本有问题,但是如何解决?

我试过:

npm cache clean --force commands
npm install -g npm-install-peers
npm install --legacy-peer-deps

使用 npm install --save-dev vuex@next 安装时出现此错误

我的 package.json 文件:

"name": "",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"serve:standalone": "vue-cli-service serve --mode standalone"
},
"dependencies": {
"core-js": "^3.6.5",
"devextreme": "21.2.5",
"devextreme-vue": "21.2.5",
"single-spa-vue": "^2.1.0",
"vue": "^2.6.11"
},
"devDependencies": {
"@storybook/vue": "^6.4.14",
"@vue/cli": "^4.5.15",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"node-sass": "^6.0.1",
"sass-loader": "^10",
"eslint-plugin-vue": "^6.2.2",
"vue-cli-plugin-single-spa": "~3.1.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
  "node": true
},
"extends": [
  "plugin:vue/essential",
  "eslint:recommended"
],
"parserOptions": {
  "parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
 "not dead"
]

那是因为您正在尝试安装仅与 Vue@3 兼容的 Vuex@4。但是,您的项目正在使用 Vue@2。

您需要决定要使用哪个 Vue 版本。既然你提到你只想使用 Vue2,那么你需要安装 Vuex@3 来代替:

npm install vuex@3