Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级 node18 遇到的问题总结 #216

Open
funnycoderstar opened this issue Nov 18, 2022 · 0 comments
Open

升级 node18 遇到的问题总结 #216

funnycoderstar opened this issue Nov 18, 2022 · 0 comments
Labels

Comments

@funnycoderstar
Copy link
Owner

funnycoderstar commented Nov 18, 2022

node14 升级node18 遇到的问题

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

当前项目安装的包有对等依赖冲突。

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 方式安装。

npm7之前不会中断安装过程,会保留两个版本,一个放在一级目录,一个放到项目的目录下;npm7 升级之后,所有 peerDependencies 会自动安装,但是如何某个包的 peerDependencies 和 root 层同样报的版本冲突,会自动报错。

解决方案:

1、按照报错信息解决包版本冲突
截图中的报错只是一个示例,并不一定都是 react 这个包报错版本冲突,大部分包都会报错版本冲突。

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

2、冲突太多无法暂时全部解决的,可以暂时使用下面的方式

  • 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 信息,但是安装的组件可以正常使用

具体可查看:

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以上会存在这个问题: nodejs/node#40455

node17及以后版本中支持 OpenSSL3.0, 而OpenSSL3.0对允许算法和秘钥大小增加了严格的限制,可能会对生态系统造成一些影响。

解法:

  1. 升级最新版本的 升级webpack@5.75 及react-scripts@5.0.1

  2. 配置环境变量 NODE_OPTIONS="--openssl-legacy-provider" ,让 Nodejs 使用旧版本兼容的 OpenSSL
    https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
    具体可查看:

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.

这个问题是当时在升级发布系统的服务器的 node版本时遇到的问题

解决方案

  1. 升级到支持的操作系统内核
    参考node官方文档,推荐生产环境操作系统https://github.com/nodejs/node/blob/main/BUILDING.md

  2. 源码编译,升级gcc glibc(不推荐)

针对以上的一些问题,我们采用的大致升级计划如下

  1. 新申请一台机器,部署新的一套发布平台 newPublish,先升级 操作系统:centos,然后再安装 node18。newPublish 平台可以提供给各个项目验证,只做验证,不上线。
  2. 核心和基础服务升级node18
  3. 各项目真正的升级 node18, 使用node18的发布系统发布上线,并做好线上验证。

参考文档:

参考

@funnycoderstar funnycoderstar changed the title 升级 node18 升级 node18 遇到的问题总结 Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant