NPM: npm同级依赖冲突

7

我下载了一个项目,但没有 package-lock.json 文件。当我运行 npm install 时,出现冲突。错误信息如下:

root@fb3391c63c7f:/app/avatar/avatar-h5# npm install --registry=https://registry.npm.taobao.org
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: avatar@3.2.0
npm ERR! Found: vue@2.6.10
npm ERR! node_modules/vue
npm ERR!   vue@"2.6.10" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"3.0.5" from @vue/compiler-sfc@3.0.5
npm ERR! node_modules/@vue/compiler-sfc
npm ERR!   peer @vue/compiler-sfc@"^3.0.0-beta.14" from @vue/cli-service@4.5.10
npm ERR!   node_modules/@vue/cli-service
npm ERR!     peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.4.4
npm ERR!     node_modules/@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! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-18T21_53_07_044Z-debug.log

我阅读了很多文档,并发现@vue/cli-plugin-babel@4.4.4会安装最新的@vue/cli-service@4.5.10

我该如何安装与vue@2.6.10兼容的版本?


package.json文件

{
  "name": "avatar",
  "version": "3.2.0",

  "scripts": {
    "dev": "vue-cli-service serve",
    "build:prod": "vue-cli-service build",
    "build:stage": "vue-cli-service build --mode staging",
    "preview": "node build/index.js --preview",
    "lint": "eslint --ext .js,.vue src",
    "test:unit": "jest --clearCache && vue-cli-service test:unit",
    "test:ci": "npm run lint && npm run test:unit",
    "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml",
    "new": "plop"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.{js,vue}": [
      "eslint --fix",
      "git add"
    ]
  },
  "keywords": [
    "vue",
    "admin",
    "dashboard",
    "element-ui",
    "boilerplate",
    "admin-template",
    "management-system"
  ],
  "repository": {
    "type": "git",
    "url": "https://gitee.com/fairyfleet/avatar.git"
  },
  "dependencies": {
    "@riophae/vue-treeselect": "0.4.0",
    "axios": "0.18.1",
    "clipboard": "2.0.4",
    "core-js": "3.6.5",
    "echarts": "4.2.1",
    "element-ui": "2.13.2",
    "file-saver": "2.0.1",
    "js-beautify": "1.10.2",
    "fuse.js": "3.4.4",
    "js-cookie": "2.2.0",
    "jsencrypt": "3.0.0-rc.1",
    "normalize.css": "7.0.0",
    "nprogress": "0.2.0",
    "path-to-regexp": "2.4.0",
    "screenfull": "4.2.0",
    "sortablejs": "1.8.4",
    "vue": "2.6.10",
    "vue-count-to": "1.0.13",
    "quill": "1.3.7",
    "vue-cropper": "0.4.9",
    "vue-router": "3.0.2",
    "vue-splitpane": "1.0.4",
    "vuedraggable": "2.20.0",
    "vuex": "3.1.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "4.4.4",
    "@vue/cli-plugin-eslint": "4.4.4",
    "@vue/cli-plugin-unit-jest": "4.4.4",
    "@vue/cli-service": "4.4.4",
    "@vue/test-utils": "1.0.0-beta.29",
    "autoprefixer": "9.5.1",
    "babel-eslint": "10.1.0",
    "babel-jest": "23.6.0",
    "babel-plugin-dynamic-import-node": "2.3.3",
    "chalk": "2.4.2",
    "chokidar": "2.1.5",
    "connect": "3.6.6",
    "eslint": "6.7.2",
    "eslint-plugin-vue": "6.2.2",
    "html-webpack-plugin": "3.2.0",
    "husky": "1.3.1",
    "lint-staged": "8.1.5",
    "mockjs": "1.0.1-beta3",
    "plop": "2.3.0",
    "runjs": "4.3.2",
    "node-sass": "4.14.1",
    "sass-loader": "8.0.2",
    "script-ext-html-webpack-plugin": "2.1.3",
    "script-loader": "0.7.2",
    "serve-static": "1.13.2",
    "svg-sprite-loader": "4.1.3",
    "svgo": "1.2.0",
    "vue-template-compiler": "2.6.10"
  },
  "engines": {
    "node": ">=8.9",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ]
}

4个回答

10

我也遇到了同样的问题。这只会在较新版本的npm上出现。你可以通过退回到LTS 14.15版本的NodeJS来暂时解决它。

在Linux/MacOS上:

nvm use --lts
否则:
npm install -g npm@6.14.8

0

添加到 Chaim Zonnenberg

我在使用Node (16.11.1)和npm (8.0.0)在macOS上进行NestJS项目开发时遇到了这个错误。

当我运行命令npm install时,出现以下错误:

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: admin-gateway@0.0.1
npm ERR! Found: rxjs@7.3.0
npm ERR! node_modules/rxjs
npm ERR!   rxjs@"^6.0.0" from the root project
npm ERR!   peer rxjs@"^6.0.0 || ^7.0.0" from @nestjs/axios@0.0.1
npm ERR!   node_modules/@nestjs/axios
npm ERR!     @nestjs/axios@"^0.0.1" from the root project
npm ERR!   4 more (@nestjs/common, @nestjs/core, @nestjs/config, @nestjs/microservices)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! elastic-apm-nest@"0.0.7" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: rxjs@6.6.7
npm ERR! node_modules/rxjs
npm ERR!   peer rxjs@"^6.0.0" from elastic-apm-nest@0.0.7
npm ERR!   node_modules/elastic-apm-nest
npm ERR!     elastic-apm-nest@"0.0.7" 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.

这是我修复的方法:

问题是我正在运行一个较新的 Node 版本(16.11.1),不是长期支持 (lts) 版本。

首先,我使用 Homebrew 命令移除了我的 macOS 上存在的 Node 包:

brew uninstall --ignore-dependencies node 

然后我使用homebrew安装了nvm。
brew install nvm

接下来,我创建了NVM的工作目录,因为它不存在:
mkdir ~/.nvm

接下来,我将以下内容添加到~/.zshrc文件或您所需的shell配置文件中。对于我来说,~/.zshrc文件不存在,所以我使用命令touch ~/.zshrc创建了它,然后使用命令打开了它:
nano ~/.zshrc

并在下面添加以下内容:

export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

使用键盘组合Ctrl + X保存文件,然后按下YENTER

接下来,打开一个新的终端,并使用以下命令安装Node LTS版本:

nvm install --lts

如果您已经安装了Node LTS版本,请运行以下命令:
nvm use --lts

使用以下命令确认您的 Node 和 npm 版本:
node --version
npm --version

最后,再次运行npm install命令,这次一切都会顺利进行。

0
我解决这个问题的方法很简单,只需要删除 node_modules 文件夹,然后将包版本粘贴到 package json 文件中并运行 npm install 即可。

-3

npm install -g npm@6.14.8

这个命令在 Windows 上同样适用。


3
这已经是 https://dev59.com/uL_qa4cB1Zd3GeqPARhx#66043059 已经阐述的内容,无需重复。 - Eric Aya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接