报错: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.

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

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

相关推荐
堕落年代3 分钟前
Vue主流的状态保存框架对比
前端·javascript·vue.js
OpenTiny社区14 分钟前
TinyVue的DatePicker 组件支持日期面板单独使用啦!
前端·vue.js
冴羽15 分钟前
Svelte 最新中文文档教程(22)—— Svelte 5 迁移指南
前端·javascript·svelte
树上有只程序猿19 分钟前
Vue3组件通信:多个实战场景,轻松玩转复杂数据流!
前端·vue.js
m0_7482522322 分钟前
Python 入门教程(2)搭建环境 2.4、VSCode配置Node.js运行环境
vscode·python·node.js
剪刀石头布啊26 分钟前
css属性值计算过程
前端·css
bin915331 分钟前
DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14基础固定表头示例
前端·javascript·vue.js·ecmascript·deepseek
小华同学ai33 分钟前
吊打中文合成!这款开源语音神器效果炸裂,逼真到离谱!
前端·后端·github
颜酱39 分钟前
后台系统从零搭建(三)—— 具体页面之部门管理(抽离通用的增删改查逻辑)
前端·javascript·react.js
qq_3325394539 分钟前
JavaScript性能优化实战指南
前端·javascript·性能优化