nodeJS14 升级 node18 遇到的问题记录

2023-02-0710:05:31WEB前端开发Comments2,775 views字数 3823阅读模式

1. npm i 报错 ERESOLVE could not resolve 或RESOLVE unable to resolve dependency tree(无法解析依赖关系树)

当前项目安装的包有对等依赖冲突。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @nestjs/elasticsearch@8.1.0
npm ERR! Found: @elastic/elasticsearch@5.6.22
npm ERR! node_modules/@elastic/elasticsearch
npm ERR!   @elastic/elasticsearch@"~5.6.22" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @elastic/elasticsearch@"^7.4.0 || ^8.0.0" from @nestjs/elasticsearch@8.1.0
npm ERR! node_modules/@nestjs/elasticsearch
npm ERR!   @nestjs/elasticsearch@"~8.1.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @elastic/elasticsearch@8.2.1
npm ERR! node_modules/@elastic/elasticsearch
npm ERR!   peer @elastic/elasticsearch@"^7.4.0 || ^8.0.0" from @nestjs/elasticsearch@8.1.0
npm ERR!   node_modules/@nestjs/elasticsearch
npm ERR!     @nestjs/elasticsearch@"~8.1.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

原因:

npm7 将 install 方式默认为按照 peer dependencies 方式安装。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

npm7之前不会中断安装过程,会保留两个版本,一个放在一级目录,一个放到项目的目录下;npm7 升级之后,所有 peerDependencies 会自动安装,但是如何某个包的 peerDependencies 和 root 层同样报的版本冲突,会自动报错。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

解决方案:

1、按照报错信息解决包版本冲突
截图中的报错只是一个示例,并不一定都是 react 这个包报错版本冲突,大部分包都会报错版本冲突。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

  • 如果是内部的包,可以直接在内部包加 peer 解决版本冲突或者解决版本冲突
  • 外部 npm 的包,可以去看一下版本是否可以兼容

2、冲突太多无法暂时全部解决的,可以暂时使用下面的方式文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

  • npm install --force 或 npm install --legacy-peer-deps
  • .npmrc 文件配置 legacy-peer-deps = true
    npm i -- force // 强制 npm 从远端获取资源,即使磁盘上存在副本
    npm i --legacy-peer-deps // 绕过 peerDependency里的依赖自动安装,它告诉npm忽略项目中引入的各个依赖模块之前依赖相同但版本不同的问题,以npmV3-V6的方式继续执行安装操作。所以其实该命令并没有真的解决冲突,而是忽略了冲突,以“过时”(v3-v6)的方式进行下载操作

    使用上述方法后,不会弹出报错信息,只是直接跳过安装依赖,不能解决包的使用问题。解决问题的办法就是手动在顶层安装冲突的依赖,虽然出现一些 warning 信息,但是安装的组件可以正常使用

具体可查看:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

2. npm run build / start 报错 Error:error:0308010C:digital enveloperoutines::unsupported

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/github/myProject/socket/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/github/myProject/socket/node_modules/webpack/lib/NormalModule.js:417:16)
   ...
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

原因:

node17以上会存在这个问题: https://github.com/nodejs/nod...文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

node17及以后版本中支持 OpenSSL3.0, 而OpenSSL3.0对允许算法和秘钥大小增加了严格的限制,可能会对生态系统造成一些影响。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

解法:

  1. 升级最新版本的 升级webpack@5.75 及react-scripts@5.0.1
  2. 配置环境变量 NODE_OPTIONS="--openssl-legacy-provider" ,让 Nodejs 使用旧版本兼容的 OpenSSL
    参考: https://stackoverflow.com/que...
    具体可查看:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

3. centos7 环境 使用node18 的报错

# root @ centos7-build in ~/node-v18.3.0-linux-x64/bin [9:20:05] 
$ ./node
./node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by ./node)
./node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by ./node)
./node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./node)
./node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./node)
./node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./node)
./node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./node)

原因

Starting v18, Node.js no longer supports centos 7 and a few other Linux distros due to glibc version incompatibility. See NodeJS 18 revert to building on CentOS 7, RHEL 7, Ubuntu Bionic 18.04, other other LTS distros · Iss.文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

这个问题是当时在升级发布系统的服务器的 node版本时遇到的问题文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

解决方案

  1. 升级到支持的操作系统内核
    参考node官方文档,推荐生产环境操作系统https://github.com/nodejs/nod...
  2. 源码编译,升级gcc glibc(不推荐)

参考文档:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html

参考

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/30724.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/gcs/30724.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定