You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

npm install(invenio-cli install)时Peer Dependencies冲突问题求助

解决React+TypeScript项目中npm install的Peer Dependencies冲突问题

问题描述

使用Node.js 12.22.9、npm 9.8.1,在基于React和TypeScript的InvenioILS项目中执行npm install或invenio-cli install时,遭遇Peer Dependencies冲突,报错如下:

npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: @typescript-eslint/eslint-plugin@2.34.0
npm ERR! Found: eslint@7.32.0
npm ERR! Conflicting peer dependency: eslint@6.8.0

项目信息

项目结构

- Project root
  - package.json
  - node_modules
  - ... (other project files)

项目package.json内容

{
  "name": "hmm",
  "version": "1.0.0",
  "description": "Welcome to your InvenioILS instance.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "npm install --force"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@ckeditor/ckeditor5-react": "2.1.0",
    "@craco/craco": "5.9.0",
    "@emotion/core": "^11.0.0",
    "@emotion/react": "11.7.0",
    "@hookform/error-message": "1.1.0",
    "@hookform/resolvers": "1.1.0",
    "@testing-library/jest-dom": "5.14.1",
    "@testing-library/react": "12.0.0",
    "@testing-library/user-event": "13.1.9",
    "@types/classnames": "2.3.1",
    "@types/lodash": "4.14.173",
    "@types/react": "17.0.37",
    "@types/react-dom": "17.0.11",
    "@typescript-eslint/eslint-plugin": "2.34.0",
    "@typescript-eslint/parser": "2.34.0",
    "axios": "^0.21.4",
    "classnames": "2.3.1",
    "eslint-plugin-flowtype": "5.8.0",
    "eslint-plugin-import": "2.25.3",
    "eslint-plugin-jsx-a11y": "6.4.1",
    "eslint-plugin-react": "7.26.1",
    "eslint-plugin-react-hooks": "4.3.0",
    "lodash": "4.17.21",
    "query-string": "7.0.1",
    "react": "16.14.0",
    "react-dom": "16.14.0",
    "react-invenio-forms": "2.4.0",
    "react-select": "^5.0.0",
    "react-toastify": "8.0.3",
    "react-transition-group": "4.4.2",
    "recoil": "0.3.1",
    "sweetalert2": "11.1.0",
    "yup": "0.32.11"
  },
  "devDependencies": {
    "eslint": "7.32.0",
    "@typescript-eslint/parser": "2.34.0",
    "eslint-config-react-app": "5.2.1"
  },
  "resolutions": {
    "eslint": "^7.32.0",
    "eslint-config-react-app": "^5.2.1",
    "@typescript-eslint/parser": "^2.34.0"
  }
}

已尝试的无效操作

  • npm install --force
  • npm install --legacy-peer-deps

相关命令输出

npm list 输出

algorithmx@Torime:~/hmm$ npm list
hmm@1.0.0 \\wsl.localhost\Ubuntu\home\algorithmx\hmm
+-- @ckeditor/ckeditor5-react@2.1.0
+-- @craco/craco@5.9.0
+-- @emotion/core@11.0.0
+-- @emotion/react@11.7.0
+-- @hookform/error-message@1.1.0
+-- @hookform/resolvers@1.1.0
+-- @testing-library/jest-dom@5.14.1
+-- @testing-library/react@12.0.0
+-- @testing-library/user-event@13.1.9
+-- @types/classnames@2.3.1
+-- @types/lodash@4.14.173
+-- @types/react-dom@17.0.11
+-- @types/react@17.0.37
+-- @typescript-eslint/eslint-plugin@2.34.0
+-- @typescript-eslint/parser@2.34.0
+-- axios@0.21.4
+-- classnames@2.3.1
+-- eslint-config-react-app@5.2.1
+-- eslint-plugin-flowtype@5.8.0
+-- eslint-plugin-import@2.25.3
+-- eslint-plugin-jsx-a11y@6.4.1
+-- eslint-plugin-react-hooks@4.3.0
+-- eslint-plugin-react@7.26.1
+-- eslint@7.32.0
+-- lodash@4.17.21
+-- query-string@7.0.1
+-- react-dom@16.14.0
+-- react-invenio-forms@2.4.0
+-- react-select@5.7.4
+-- react-toastify@8.0.3
+-- react-transition-group@4.4.2
+-- react@16.14.0
+-- recoil@0.3.1
+-- sweetalert2@11.1.0
`-- yup@0.32.11

npm outdated 输出

algorithmx@Torime:~/hmm$ npm outdated
Package                            Current    Wanted    Latest  Location
 Depended by
@ckeditor/ckeditor5-react            2.1.0     2.1.0     6.1.0  node_modules/@ckeditor/ckeditor5-react         hmm
@craco/craco                         5.9.0     5.9.0     7.1.0  node_modules/@craco/craco
 hmm
@emotion/react                      11.7.0    11.7.0   11.11.1  node_modules/@emotion/react
 hmm
@hookform/error-message              1.1.0     1.1.0     2.0.1  node_modules/@hookform/error-message
 hmm
@hookform/resolvers                  1.1.0     1.1.0     3.1.1  node_modules/@hookform/resolvers
 hmm
@testing-library/jest-dom           5.14.1    5.14.1    5.17.0  node_modules/@testing-library/jest-dom         hmm
@testing-library/react              12.0.0    12.0.0    14.0.0  node_modules/@testing-library/react
 hmm
@testing-library/user-event         13.1.9    13.1.9    14.4.3  node_modules/@testing-library/user-event       hmm
@types/lodash                     4.14.173  4.14.173  4.14.196  node_modules/@types/lodash
 hmm
@types/react                       17.0.37   17.0.37   18.2.17  node_modules/@types/react
 hmm
@types/react-dom                   17.0.11   17.0.11    18.2.7  node_modules/@types/react-dom
 hmm
@typescript-eslint/eslint-plugin    2.34.0    2.34.0     6.2.0  node_modules/@typescript-eslint/eslint-plugin  hmm
@typescript-eslint/parser           2.34.0    2.34.0     6.2.0  node_modules/@typescript-eslint/parser         hmm
axios                               0.21.4    0.21.4     1.4.0  node_modules/axios
 hmm
classnames                           2.3.1     2.3.1     2.3.2  node_modules/classnames
 hmm
eslint                              7.32.0    7.32.0    8.46.0  node_modules/eslint
 hmm
eslint-config-react-app              5.2.1     5.2.1     7.0.1  node_modules/eslint-config-react-app
 hmm
eslint-plugin-flowtype               5.8.0     5.8.0     8.0.3  node_modules/eslint-plugin-flowtype
 hmm
eslint-plugin-import                2.25.3    2.25.3    2.28.0  node_modules/eslint-plugin-import
 hmm
eslint-plugin-jsx-a11y               6.4.1     6.4.1     6.7.1  node_modules/eslint-plugin-jsx-a11y
 hmm
eslint-plugin-react                 7.26.1    7.26.1    7.33.1  node_modules/eslint-plugin-react
 hmm
eslint-plugin-react-hooks            4.3.0     4.3.0     4.6.0  node_modules/eslint-plugin-react-hooks         hmm
query-string                         7.0.1     7.0.1     8.1.0  node_modules/query-string
 hmm
react                              16.14.0   16.14.0    18.2.0  node_modules/react
 hmm
react-dom                          16.14.0   16.14.0    18.2.0  node_modules/react-dom
 hmm
react-toastify                       8.0.3     8.0.3     9.1.3  node_modules/react-toastify
 hmm
react-transition-group               4.4.2     4.4.2     4.4.5  node_modules/react-transition-group
 hmm
recoil                               0.3.1     0.3.1     0.7.7  node_modules/recoil
 hmm
sweetalert2                         11.1.0    11.1.0   11.7.20  node_modules/sweetalert2
 hmm
yup                                0.32.11   0.32.11     1.2.0  node_modules/yup
 hmm

npm list -g --depth=0 输出

algorithmx@Torime:~/hmm$ npm list -g --depth=0
C:\Users\Sammie\AppData\Roaming\npm
+-- @exlibris/exl-cloudapp-cli@1.4.7
+-- node-sass@
`-- npm@9.8.1

解决方案

冲突根源是@typescript-eslint/eslint-plugin@2.34.0仅支持eslint@6.x版本,但项目中安装的是eslint@7.32.0,以下是两种可行解决路径:

路径一:降级ESLint到兼容版本

  1. 修改package.json中的devDependencies和resolutions,将eslint版本改为6.8.0:
    "devDependencies": {
      "eslint": "6.8.0",
      // 其他依赖保持不变
    },
    "resolutions": {
      "eslint": "^6.8.0",
      // 其他resolutions保持不变
    }
    
  2. 删除项目根目录下的node_modules文件夹和package-lock.json文件
  3. 执行npm install重新安装依赖

路径二:升级@typescript-eslint插件到兼容ESLint7的版本

@typescript-eslint从3.x版本开始支持ESLint7,可升级到3.x系列的最新版本(如3.10.1),同时保持ESLint7版本:

  1. 修改package.json中的dependencies和devDependencies,更新@typescript-eslint相关依赖:
    "dependencies": {
      "@typescript-eslint/eslint-plugin": "3.10.1",
      "@typescript-eslint/parser": "3.10.1",
      // 其他依赖保持不变
    },
    "devDependencies": {
      "@typescript-eslint/parser": "3.10.1",
      // 其他依赖保持不变
    },
    "resolutions": {
      "@typescript-eslint/parser": "^3.10.1",
      // 其他resolutions保持不变
    }
    
  2. 删除node_modules和package-lock.json
  3. 执行npm install重新安装依赖

额外注意事项

  • 若使用invenio-cli install,需确保修改后的package.json符合InvenioILS的依赖要求,避免后续命令执行异常
  • 升级或降级依赖后,建议运行项目测试是否存在功能异常

内容的提问来源于stack exchange,提问作者Samuel Adu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 09:04:52