报错: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: acorn-jsx@5.3.2
npm WARN Found: acorn@7.4.1
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 acorn-jsx@5.3.2
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from espree@9.6.1
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 acorn@7.4.1

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 acorn@7.4.1
bash 复制代码
 % npm install acorn@7.4.1
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: acorn-jsx@5.3.2
npm WARN Found: acorn@7.4.1
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 acorn-jsx@5.3.2
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from espree@9.6.1
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: acorn-jsx@5.3.2
npm WARN Found: acorn@7.4.1
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 acorn-jsx@5.3.2
npm WARN node_modules/acorn-jsx
npm WARN   acorn-jsx@"^5.3.2" from espree@9.6.1
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.

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

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

相关推荐
ZC跨境爬虫11 小时前
跟着 MDN 学 HTML day_33:(Attr 接口与属性节点的深入理解)
前端·javascript·ui·html·音视频·html5
神所夸赞的夏天11 小时前
如何获取多层json数据,存成dictionary,并取最大最小值
java·前端·json
红色的小鳄鱼11 小时前
前端面试js手写
开发语言·前端·javascript
焦糖玛奇朵婷11 小时前
健身房预约小程序开发、设计
java·大数据·服务器·前端·小程序
上海云盾王帅11 小时前
WEB业务如何接入安全防护:从零到一的实战指南
前端·安全
用户0595401744611 小时前
AI Agent记忆丢失踩坑实录:这个问题让我排查了3天
前端·css
web行路人11 小时前
前端对Commands(斜杠命令)一些常用
前端·javascript·vue.js·vue
当时只道寻常11 小时前
从零到一打造企业级全栈后台管理系统 —— 技术选型、工程化实践与深度思考
前端·全栈·前端工程化
竹林81811 小时前
用 ethers.js 连 MetaMask 做钱包登录,我踩了三个坑才搞定跨页面状态同步
前端·javascript
饺子不吃醋11 小时前
深入理解 Vue 3 的 setup(含 Composition API)
前端·vue.js