NPM:npm peer dependency conflict

f3temu5u  于 2023-06-23  发布在  其他
关注(0)|答案(4)|浏览(141)

我下载了一个项目,它没有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"
  ]
}
rekjcdws

rekjcdws1#

同样的问题。它只发生在较新版本的npm上。您可以暂时修复它,方法是使用LTS 14.15版本的NodeJS。
在Linux/MacOS上:

nvm use --lts

否则:

npm install -g npm@6.14.8
voase2hg

voase2hg2#

对我来说,解决这个问题的方法是简单地删除node_modules文件夹,然后将包版本粘贴到包json文件中并运行npm install。

xam8gpfp

xam8gpfp3#

添加到Chaim Zonnenberg
我在macOS上使用Node(16.11.1)和npm(8.0.0)处理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

然后我安装了nvm使用homebrew

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命令,这一次一切都会正常。

polhcujo

polhcujo4#

npm install -g npm@6.14.8
这也适用于Windows。

相关问题