Node.js 18 发行注记


Red Hat build of Node.js 18

用于 Node.js 18 LTS

Red Hat Customer Content Services

摘要

本发行注记包含与 Node.js 18 LTS 相关的重要信息。

前言

发行版本日期:2023 年 1 月 31 日

第 1 章 所需的基础架构组件版本

在使用红帽构建的 Node.js 时,需要以下基础架构组件。除了明确指定为支持的组件外,红帽不提供对这些组件的支持。

Expand
组件名称版本

Nodeshift

2.1.1

npm 8

8.19.2

OpenShift Container Platform (OCP)[a]

3.11, 4.5

git

2.0 或更高版本

oc 命令行工具

3.11 或更高版本[b]

[a] 红帽支持 OCP
[b] oc CLI 工具的版本应该与您正在使用的 OCP 版本对应。

第 2 章 功能

本节包含有关红帽构建的 Node.js 18 发行版本中引入的功能更改的信息。

2.1. 新特性和更改的功能

Node.js 18 LTS 有以下红帽构建的 Node.js 支持的新功能和增强。

有关 Node.js 18 LTS 的详细信息,请参阅上游发行注记上游文档

2.1.1. V8 JavaScript 引擎升级到 v10.2

此发行版本包括将 V8 JavaScript 引擎升级到 v10.2,它是 Chromium 101 的一部分。

升级的 V8 JavaScript 引擎包括以下新功能和增强:

有关 V8 JavaScript 引擎中可用更改的更多信息,请参阅 V8 博客

2.1.2. HTTP 超时的默认值

此发行版本包括 HTTP 超时的以下改进:

  • server.headersTimeout 属性限制解析器等待接收完整 HTTP 标头的时间长度,现在的默认值为 60000 毫秒(60 秒)。
  • server.requestTimeout 属性限制服务器从客户端接收整个请求的时间长度,现在的默认值为 300000 毫秒(5 分钟)。

如果这些超时过期,服务器会返回 408 错误,并在不将请求监听程序转发到请求监听程序的情况下关闭连接。

注意

当服务器的前面没有部署反向代理时,要防止出现拒绝服务攻击的情况,请确保将这些超时值设置为不是0 的值。

2.1.3. 全局范围内的 Blob 和 BroadcastChannel API。

以下 API 现在被完全支持,并作为全局对象提供:

  • Blob 类封装可在多个 worker 线程之间安全共享的不可变原始数据。blob缓冲 类的子类。
  • BroadcastChannel 类使异步一对多通信与绑定到同一频道名称的所有其他广播频道实例进行通信。BroadcastChannel 扩展 EventTarget 类。

在以前的版本中,这些 API 只是一个技术预览功能。

2.2. 已弃用的功能

在 Red Hat build of Node.js 18 发行版本中,以下功能已弃用。

注意

有关本发行版本中已弃用或删除的功能的更多信息,请参阅 nodejs.org 网站

当对象有自己的 toString 属性在以下任一方法中作为参数传递时,这个版本包括隐式对象到字符串的运行时弃用:

  • fs.write()
  • fs.writeFile()
  • fs.appendFile()
  • fs.writeFileSync()
  • fs.appendFileSync()

作为字符串 coercion 的替代选择,将对象转换为原语字符串。

此发行版本删除了在 dns.lookup ()dnsPromises.lookup () 方法中作为参数传递的选项类型。如果您使用以下任一选项类型和值组合,Node.js 现在会抛出 ERR_INVALID_ARG_TYPE 错误:

  • family 选项的非空的非整数值
  • hints 选项的一个非空的非数字值
  • all 选项的一个非空的、非布尔类型的值
  • verbatim 选项的非空非布尔值

2.2.3. multipleResolves的运行时弃用

此发行版本包括 multipleResolves 进程事件的运行时弃用。例如:

process.on('multipleResolves', handler)
Copy to Clipboard Toggle word wrap

multipleResolves 事件不适用于 V8 承诺组合器,这会影响此事件的有用性和可靠性,以便在使用 Promise 构造器时跟踪潜在的错误。例如,Promise.race () 方法也可以触发 multipleResolves 事件,这不一定表示错误。

2.2.4. 对 thenable 对象的支持

此发行版本在流实现方法中返回 thenable 对象的功能。使用 thenable 对象可能会导致意外问题,例如,用户以回调风格实现函数,但使用 async 方法。这种类型的实现会导致承诺和回调语义无效。

例如:

const w = new Writable({
  async final(callback) {
    await someOp();
    callback();
  },
});
Copy to Clipboard Toggle word wrap

作为 thenable 对象的替代选择,使用回调,对于流实现方法避免使用 async 函数。

2.2.5. tls.parseCertString()

此发行版本删除了 tls.parseCertString () 方法,这是解析证书主题和签发者字符串的解析程序帮助程序。tls.parseCertString () 方法无法正确处理多值 Relative Distinguished Names (RDN),这可能会导致不正确的表示和安全问题。

另外,_tls_common.translatePeerCertificate 不再转换 subject 和 issuer 属性。

注意

早期版本的 Node.js 建议使用 querystring.parse () 方法作为 tls.parseCertString () 的替代选择。但是,因为 querystring.parse () 也无法正确处理所有证书主题,这个版本不再建议使用 querystring.parse () 作为替代方案。

2.3. 技术预览功能

在 Node.js 18 LTS 版本中,以下功能作为技术预览功能提供。

2.3.1. fetch API

提供了一个实验性的 fetch API,作为一个全局对象。fetch API 基于 Undici,它是 Node.js 的 HTTP/1.1 客户端,以及提供 Fetch Web API 的 Node.js 实现的 node-fetch 模块。

例如:

const res = await fetch('https://nodejs.org/api/documentation.json');
if (res.ok) {
  const data = await res.json();
  console.log(data);
}
Copy to Clipboard Toggle word wrap

由于这个改进,现在可使用以下全局对象:

  • fetch (与浏览器兼容 fetch () 函数的版本)
  • FormData (一个与浏览器兼容 FormData 接口的版本)
  • 标头 (与浏览器兼容标头接口的 版本
  • Request (一个与浏览器兼容的 Request 接口版本)
  • 响应 (与浏览器兼容的 Response 接口版本)

您可以使用 --no-experimental-fetch 命令行选项禁用 fetch API。

2.3.2. 全局范围内的 Web Streams API

Web Streams API 在 Red Hat build of Node.js 16 版本中作为技术预览功能引进。在这个发行版本中,Node.js 现在会在全局范围内公开 Web Streams API。这会取代之前版本中的行为,其中 Web Streams API 只能通过 stream/web 核心模块访问。

因此,以下 API 现在作为全局对象提供:

ReadableStreamReadableStreamDefaultReaderReadableStreamBYOBReaderReadableStreamBYOBRequestReadableByteStreamControllerReadableStreamDefaultController, TransformStreamTransformStreamDefaultControllerWritableStreamWritableStreamDefaultWriterWritableStreamDefaultControllerByteLengthQueuingStrategy, CountQueuingStrategyTextEncoderStreamTextDecoderStreamCompressionStreamDecompressionStream

ESM Loader Hooks API 在 Red Hat build of Node.js 16 版本中作为技术预览功能引进。ESM Loader Hooks API 现在支持多个自定义加载程序。

要使多个加载程序协同工作,此功能使用名为 chaining 的进程,这类似于一个承诺链。 例如,第一次加载器 调用 第二加载器第二加载器 调用 第三个加载器,以此类推。

注意

如果自定义加载程序没有有意调用链中的下一加载程序,自定义加载程序必须向短电路发送信号。

如需更多信息,请参阅 Node.js ECMAScript 模块文档

2.3.4. watch 模式

现在,您可以使用 node --watch 选项以监视模式运行 Node.js 应用程序。

以监视模式运行应用程序意味着,如果修改导入的文件,进程将重新启动。

2.4. 支持的构架

Node.js 构建器镜像和 RPM 软件包可用,并支持与以下 CPU 架构一起使用:

  • AMD x86_64
  • ARM64
  • OpenShift 环境中的 IBM Z (s390x)
  • OpenShift 环境中的 IBM Power 系统(ppc64le)

第 3 章 发行组件

第 4 章 修复的问题

此发行版本在 Node.js 18 LTS 社区版本中包含了所有修复的问题。

第 5 章 已知问题

没有影响此版本的已知问题。

第 6 章 影响所需基础架构组件的已知问题

没有已知的、会影响到此版本所需基础架构组件的问题。

法律通告

Copyright © 2024 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat