首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用vue-cli创建的Vue 2项目的npm更新失败。

用vue-cli创建的Vue 2项目的npm更新失败。
EN

Stack Overflow用户
提问于 2021-03-06 13:24:41
回答 2查看 3.1K关注 0票数 1

我用vue-cli创建了一个Vue 2项目,并尝试运行npm update。不幸的是,我收到以下错误:

代码语言:javascript
运行
复制
{
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: test-vue@0.1.0
npm ERR! Found: vue@2.6.12
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.7" from @vue/compiler-sfc@3.0.7
npm ERR! node_modules/@vue/compiler-sfc
npm ERR!   peerOptional @vue/compiler-sfc@"^3.0.0-beta.14" from @vue/cli-service@4.5.11
npm ERR!   node_modules/@vue/cli-service
npm ERR!     dev @vue/cli-service@"~4.5.0" from the root project
npm ERR!     1 more (@vue/cli-plugin-babel)
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! 

我的package.json看起来是这样的:

代码语言:javascript
运行
复制
{
  "name": "test-vue",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@turf/turf": "^6.3.0",
    "bootstrap": "^4.5.3",
    "core-js": "^3.6.5",
    "leaflet": "^1.7.1",
    "leaflet-geodesy": "^0.2.1",
    "vue": "~2.6.11",
    "vue-router": "~3.2.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^6.2.2",
    "prettier": "^1.19.1",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "~2.6.11"
  }
}

我认为~package.json中应该防止升级到Vue 3?

感谢你的帮助!

编辑:尝试使用ncu -u作为建议

代码语言:javascript
运行
复制
PS E:\projects\test-vue> ncu -u
Upgrading E:\projects\test-vue\package.json
[====================] 20/20 100%
 core-js                  ^3.6.5  →   ^3.9.1
 vue                     ~2.6.11  →  ~2.6.12
 vue-router               ~3.2.0  →   ~3.5.1
 @vue/cli-plugin-babel    ~4.5.0  →  ~4.5.11
 @vue/cli-plugin-eslint   ~4.5.0  →  ~4.5.11
 @vue/cli-plugin-router   ~4.5.0  →  ~4.5.11
 @vue/cli-service         ~4.5.0  →  ~4.5.11
 eslint                   ^6.7.2  →  ^7.21.0
 eslint-plugin-prettier   ^3.1.3  →   ^3.3.1
 eslint-plugin-vue        ^6.2.2  →   ^7.7.0
 prettier                ^1.19.1  →   ^2.2.1
 sass                    ^1.26.5  →  ^1.32.8
 sass-loader              ^8.0.2  →  ^11.0.1
 vue-template-compiler   ~2.6.11  →  ~2.6.12

Run npm install to install new versions.

PS E:\projects\test-vue> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: webpack@5.24.3
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.0.0 || ^5.0.0" from @soda/friendly-errors-webpack-plugin@1.8.0
npm ERR!   node_modules/@soda/friendly-errors-webpack-plugin
npm ERR!     @soda/friendly-errors-webpack-plugin@"^1.7.1" from @vue/cli-service@4.5.11
npm ERR!     node_modules/@vue/cli-service
npm ERR!       dev @vue/cli-service@"~4.5.11" from the root project
npm ERR!       4 more (@vue/cli-plugin-babel, @vue/cli-plugin-eslint, ...)
npm ERR!   peer webpack@">=4.0.0" from @vue/preload-webpack-plugin@1.1.2
npm ERR!   node_modules/@vue/preload-webpack-plugin
npm ERR!     @vue/preload-webpack-plugin@"^1.1.0" from @vue/cli-service@4.5.11
npm ERR!     node_modules/@vue/cli-service
npm ERR!       dev @vue/cli-service@"~4.5.11" from the root project
npm ERR!       4 more (@vue/cli-plugin-babel, @vue/cli-plugin-eslint, ...)
npm ERR!   8 more (babel-loader, copy-webpack-plugin, css-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.0.0" from @intervolga/optimize-cssnano-plugin@1.0.6
npm ERR! node_modules/@intervolga/optimize-cssnano-plugin
npm ERR!   @intervolga/optimize-cssnano-plugin@"^1.0.5" from @vue/cli-service@4.5.11
npm ERR!   node_modules/@vue/cli-service
npm ERR!     dev @vue/cli-service@"~4.5.11" from the root project
npm ERR!     4 more (@vue/cli-plugin-babel, @vue/cli-plugin-eslint, ...)
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 C:\Users\Admin\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\Admin\AppData\Local\npm-cache\_logs\2021-03-06T19_52_21_583Z-debug.log
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-20 11:40:14

存在一些依赖关系的问题。通过使用vue-cli创建一个新项目并在那里复制package.json,我终于解决了这个问题。

编辑:您必须确保使用所有依赖项的兼容版本。-最好的方法是用vue-cli生成一个项目,以获得兼容的版本。

长话短说:不要弄乱依赖项

票数 -2
EN

Stack Overflow用户

发布于 2021-03-06 13:39:28

也许您可以尝试npm i -g npm-check-updates,然后在根文件夹中尝试执行ncu -u,这将更新您的依赖项devDependencies和peerDependencies。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66506119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档