安装vuex
使用npm安装
npm i vuex
报错
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: vue_test@0.1.0
npm ERR! Found: vue@2.6.14
npm ERR! node_modules/vue
npm ERR! vue@"^2.6.11" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^3.0.2" from vuex@4.0.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! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! See C:\Users\ASUS\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ASUS\AppData\Local\npm-cache\_logs\2022-02-11T06_28_45_753Z-debug.log
改变安装方法,使用yarn安装
npm install -g yarn //全局安装yarn
yarn add vuex //安装vuex
在package.json中查看是否安装成功
"dependencies": {
"animate.css": "^4.1.1",
"axios": "^0.25.0",
"chromedriver": "^98.0.0",
"core-js": "^3.6.5",
"nanoid": "^3.2.0",
"pubsub-js": "^1.9.4",
"vue": "^2.6.11",
"vue-resource": "^1.5.3",
"vuex": "^4.0.2"
},
追加解决办法与其他的坑
在命令行中加入–legacy-peer-deps也可以使用npm下载vuex
npm install --legacy-peer-deps vuex@3.6.2
这里注意:命令行后面的@3.6.2是为了指定vuex的版本。我是使用vue2搭建的脚手架,如果不加指定版本,会下载最新的vuex版本。在我new Vue.store({})时,页面控制台出现下面错误:
TypeError:Object(...) is not a function
出现上面错误,可能是由于版本兼容问题。