首页 前端知识 报错:npm WARN ERESOLVE overriding peer dependency

报错:npm WARN ERESOLVE overriding peer dependency

2024-04-21 10:04:05 前端知识 前端哥 614 97 我要收藏

npm WARN ERESOLVE overriding peer dependency

% 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缓存

npm cache clean --force

2. 安装特定版本的依赖

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

npm install acorn@7.4.1

3. 使用npm-force-resolutions

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

  • 安装npm-force-resolutions:
    npm install -g npm-force-resolutions
    
  • 在项目根目录创建一个resolutions文件:
    {
      "acorn": "7.4.1"
    }
    
  • 运行npm-force-resolutions:
    npx npm-force-resolutions
    
  • 最后运行npm install以安装解决方案。

4. 手动解决依赖冲突

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

5. 解决过程记录

npm cache clean --force
 % 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
npm install acorn@7.4.1
 % 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
npm install -g npm-force-resolutions
% 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,可以使用以下命令:

    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 上的证书过期引起的,可以等待一段时间,直到他们修复了这个问题。

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

npm install -g npm-force-resolutions
 % npm install -g npm-force-resolutions

added 6 packages, and audited 7 packages in 3s

found 0 vulnerabilities

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

{
  "acorn": "7.4.1"
}
npx npm-force-resolutions
% 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 工具来解决依赖冲突。

npm install
 % 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.

npx npm-force-resolutions
npm install swiper   
% 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.

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

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

转载请注明出处或者链接地址:https://www.qianduange.cn//article/5613.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!