5

我下载了一个项目,它没有文件。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将安装 lastest @vue/cli-service@4.5.10。我怎样才能安装它兼容vue@2.6.10


包.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

4 回答 4

7

这里同样的问题。它仅发生在较新版本的 npm 上。您可以通过使用 LTS 14.15 版本的 NodeJS 来临时修复它。

在 Linux/MacOS 上:

nvm use --lts

要不然:

npm install -g npm@6.14.8
于 2021-02-04T09:44:06.640 回答
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 上存在的节点包:

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再次运行命令,这次一切都会好起来的。

就这样

于 2021-10-13T23:02:29.667 回答
0

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

于 2021-03-17T03:41:42.860 回答
-2

npm install -g npm@6.14.8

这也适用于 Windows。

于 2021-04-13T03:47:02.037 回答