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

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

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

相关推荐
码爸21 分钟前
flink doris批量sink
java·前端·flink
深情废杨杨22 分钟前
前端vue-父传子
前端·javascript·vue.js
J不A秃V头A1 小时前
Vue3:编写一个插件(进阶)
前端·vue.js
司篂篂2 小时前
axios二次封装
前端·javascript·vue.js
姚*鸿的博客2 小时前
pinia在vue3中的使用
前端·javascript·vue.js
宇文仲竹3 小时前
edge 插件 iframe 读取
前端·edge
Kika写代码3 小时前
【基于轻量型架构的WEB开发】【章节作业】
前端·oracle·架构
天下无贼!4 小时前
2024年最新版Vue3学习笔记
前端·vue.js·笔记·学习·vue
Jiaberrr4 小时前
JS实现树形结构数据中特定节点及其子节点显示属性设置的技巧(可用于树形节点过滤筛选)
前端·javascript·tree·树形·过滤筛选
赵啸林4 小时前
npm发布插件超级简单版
前端·npm·node.js