报错:npm WARN ERESOLVE overriding peer dependency

npm WARN ERESOLVE overriding peer dependency

bash 复制代码
% npm install vant@2
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/acorn-jsx/node_modules/acorn
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer acorn@"^6.0.0 || ^7.0.0 || ^8.0.0" from [email protected]
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from [email protected]
npm WARN   node_modules/vue-eslint-parser/node_modules/espree
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/vant failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/phoenix/.npm/_logs/2024-03-20T08_01_18_575Z-debug-0.log

这个警告通常意味着您的项目中存在不同模块之间的依赖冲突。这可能会导致一些模块无法正常工作或版本不匹配的问题。解决这个问题的一种方法是手动调整依赖版本,以确保它们彼此兼容。

您可以尝试以下方法来解决这个警告:

1. 清除npm缓存

bash 复制代码
npm cache clean --force

2. 安装特定版本的依赖

您可以尝试手动安装特定版本的依赖来解决依赖冲突。例如:

bash 复制代码
npm install [email protected]

3. 使用npm-force-resolutions

这是一个npm包,可帮助您解决依赖冲突问题。您可以按照以下步骤使用它:

  • 安装npm-force-resolutions:

    bash 复制代码
    npm install -g npm-force-resolutions
  • 在项目根目录创建一个resolutions文件:

    json 复制代码
    {
      "acorn": "7.4.1"
    }
  • 运行npm-force-resolutions:

    bash 复制代码
    npx npm-force-resolutions
  • 最后运行npm install以安装解决方案。

4. 手动解决依赖冲突

如果以上方法都无法解决问题,您可能需要手动检查依赖关系,并尝试调整版本以解决冲突。

5. 解决过程记录

bash 复制代码
npm cache clean --force
bash 复制代码
 % npm cache clean --force
npm WARN using --force Recommended protections disabled.
phoenix@PhoenixdeMacBook-Pro enterprise-project % npm cache clean
npm ERR! As of npm@5, the npm cache self-heals from corruption issues
npm ERR!   by treating integrity mismatches as cache misses.  As a result,
npm ERR!   data extracted from the cache is guaranteed to be valid.  If you
npm ERR!   want to make sure everything is consistent, use `npm cache verify`
npm ERR!   instead.  Deleting the cache can only make npm go slower, and is
npm ERR!   not likely to correct any problems you may be encountering!
npm ERR! 
npm ERR!   On the other hand, if you're debugging an issue with the installer,
npm ERR!   or race conditions that depend on the timing of writing to an empty
npm ERR!   cache, you can use `npm install --cache /tmp/empty-cache` to use a
npm ERR!   temporary cache instead of nuking the actual one.
npm ERR! 
npm ERR!   If you're sure you want to delete the entire cache, rerun this command
npm ERR!   with --force.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/phoenix/.npm/_logs/2024-03-20T08_30_13_686Z-debug-0.log
bash 复制代码
npm install [email protected]
bash 复制代码
 % npm install [email protected]
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/acorn-jsx/node_modules/acorn
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer acorn@"^6.0.0 || ^7.0.0 || ^8.0.0" from [email protected]
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from [email protected]
npm WARN   node_modules/vue-eslint-parser/node_modules/espree
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/acorn failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/phoenix/.npm/_logs/2024-03-20T08_38_48_862Z-debug-0.log
bash 复制代码
npm install -g npm-force-resolutions
bash 复制代码
% npm install -g npm-force-resolutions
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/npm-force-resolutions failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/phoenix/.npm/_logs/2024-03-20T08_45_48_966Z-debug-0.log

由于您遇到了证书过期的问题,导致无法从 https://registry.npm.taobao.org/npm-force-resolutions 下载 npm-force-resolutions 包。这可能是由于 npm registry 上的证书过期所致。

您可以尝试以下方法来解决这个问题:

  1. 更改 registry: 尝试将 npm registry 切换到官方 registry,可以使用以下命令:

    bash 复制代码
    npm config set registry https://registry.npmjs.org/

    然后再运行 npm install -g npm-force-resolutions

  2. 手动安装 : 您可以尝试手动安装 npm-force-resolutions 包。首先,从其他源下载 npm-force-resolutions 的压缩包,然后解压缩并在解压后的文件夹内运行 npm install -g 命令。

  3. 等待修复: 如果问题是由于 npm registry 上的证书过期引起的,可以等待一段时间,直到他们修复了这个问题。

您可以尝试上述方法中的任何一种来解决这个问题。

bash 复制代码
npm install -g npm-force-resolutions
bash 复制代码
 % npm install -g npm-force-resolutions

added 6 packages, and audited 7 packages in 3s

found 0 vulnerabilities

在项目根目录创建一个resolutions文件:

bash 复制代码
{
  "acorn": "7.4.1"
}
bash 复制代码
npx npm-force-resolutions
bash 复制代码
% npx npm-force-resolutions

Error: ENOENT: no such file or directory, open './package-lock.json'
    at Object.openSync (node:fs:590:3)
    at Object.fs [as readFileSync] (node:fs:458:35)
    at npm_force_resolutions$core$node_slurp (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.cljs:15:20)
    at npm_force_resolutions$core$read_json (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.cljs:22:23)
    at switch__2144__auto__ (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.cljs:151:3)
    at /Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.cljs:151:3
    at npm_force_resolutions$core$update_package_lock_$_state_machine__2145__auto____1 (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.js:648:4)
    at cljs.core.async.impl.ioc-helpers/FN-IDX (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/npm_force_resolutions/core.js:664:88)
    at cljs.core.async.impl.ioc-helpers/run-state-machine (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/cljs/core/async/impl/ioc_helpers.cljs:35:23)
    at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (/Users/phoenix/.nvm/versions/node/v16.20.2/lib/node_modules/npm-force-resolutions/out/cljs/core/async/impl/ioc_helpers.cljs:39:6)

尝试运行 npx npm-force-resolutions 时出现了一些问题。错误信息表明没有找到 package-lock.json 文件,这是 npm-force-resolutions 工具需要使用的文件之一。

请确保您在运行 npx npm-force-resolutions 命令时,当前目录中存在 package-lock.json 文件。如果不存在,您可能需要先运行 npm install 命令来生成 package-lock.json 文件。

一旦确保 package-lock.json 文件存在,您可以再次尝试运行 npx npm-force-resolutions 命令,以便使用 npm-force-resolutions 工具来解决依赖冲突。

bash 复制代码
npm install
bash 复制代码
 % npm install
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/acorn-jsx/node_modules/acorn
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer acorn@"^6.0.0 || ^7.0.0 || ^8.0.0" from [email protected]
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from [email protected]
npm WARN   node_modules/vue-eslint-parser/node_modules/espree

removed 2 packages, changed 2 packages, and audited 895 packages in 4s

112 packages are looking for funding
  run `npm fund` for details

4 moderate severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
bash 复制代码
npx npm-force-resolutions
bash 复制代码
npm install swiper   
bash 复制代码
% npm install swiper     

added 1 package, removed 15 packages, and audited 881 packages in 10s

113 packages are looking for funding
  run `npm fund` for details

4 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

到目前为止,问题已经解决了。

请注意,解决依赖冲突可能需要一些试验和调整,以确保所有依赖关系都能正常工作。

相关推荐
小小小小宇43 分钟前
ESLint 插件笔记
前端
纪伊路上盛名在1 小时前
jupyter内核崩溃
前端·数据库·jupyter·生物信息·基因组·k-mer
Net蚂蚁代码2 小时前
Angular入门的环境准备步骤工作
前端·javascript·angular.js
小着4 小时前
vue项目页面最底部出现乱码
前端·javascript·vue.js·前端框架
lichenyang4537 小时前
React ajax中的跨域以及代理服务器
前端·react.js·ajax
呆呆的小草7 小时前
Cesium距离测量、角度测量、面积测量
开发语言·前端·javascript
一 乐8 小时前
民宿|基于java的民宿推荐系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·源码
testleaf9 小时前
前端面经整理【1】
前端·面试
好了来看下一题9 小时前
使用 React+Vite+Electron 搭建桌面应用
前端·react.js·electron
啃火龙果的兔子9 小时前
前端八股文-react篇
前端·react.js·前端框架