首页 > 解决方案 > 无法运行 NPM 安装,因为它“无法解析依赖树”

问题描述

我的 node_modules 有一些问题,所以我去删除 node_modules 并运行npm install. 男孩是一个错误。我的项目完全搞砸了。当我运行npm installnpm 它发回这个:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: project@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"15.3.0 - 16.x" from react-vis@1.11.7
npm ERR! node_modules/react-vis
npm ERR!   react-vis@"^1.11.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.
npm ERR! 
npm ERR! See /Users/Cole/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Cole/.npm/_logs/2021-05-26T10_34_07_786Z-debug.log

有人请帮助我!

编辑:这是我的 package.json。

{
  "name": "project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "axios": "^0.21.1",
    "npm": "^7.14.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.4",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.3",
    "react-vis": "^1.11.7",
    "redux": "^4.1.0",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

不太确定我做了什么是那么有害,但这是一次痛苦的经历。

运行npm audit时显示有87个漏洞。运行npm audit fix并且npm audit fix --force不修复任何东西。

有没有办法刷新所有 node_modules?回到第一格并重新安装所有依赖项?

标签: node.jsreactjsnpmcommand-line-interface

解决方案


似乎react-vis具有对等依赖项react@"15.3.0 - 16.x"。既然你有 react@17.0.2,它就会抱怨。尝试改变

"react": "^17.0.2",
"react-dom": "^17.0.2",

"react": "^16.14.0",
"react-dom": "^16.14.0",

推荐阅读