Skip to main content

警告

目录

¥Table of contents

警告

¥Warnings

Fastify 中的警告

¥Warnings In Fastify

Fastify 利用 Node.js 的 警告事件 API 通知用户已弃用的功能和已知的编码错误。Fastify 的警告可通过警告代码上的 FSTWRNFSTDEP 前缀识别。当遇到这样的警告时,强烈建议通过使用 --trace-warnings--trace-deprecation 标志来确定警告的原因。它们将生成堆栈跟踪,指出问题发生在应用代码中的位置。由于缺乏信息,未包含此信息的警告问题可能会被关闭。

¥Fastify utilizes Node.js's warning event API to notify users of deprecated features and known coding mistakes. Fastify's warnings are recognizable by the FSTWRN and FSTDEP prefixes on warning code. When encountering such a warning, it is highly recommended that the cause of the warning be determined through use of the --trace-warnings and --trace-deprecation flags. These will produce stack traces pointing out where the issue occurs in the application's code. Issues opened about warnings without including this information may be closed due to lack of information.

除了跟踪之外,还可以禁用警告。不建议理所当然地禁用警告,但如果有必要,可以使用以下任何一种方法禁用它们:

¥In addition to tracing, warnings can also be disabled. It is not recommended to disable warnings as a matter of course, but if necessary, they can be disabled by using any of the following methods:

  • NODE_NO_WARNINGS 环境变量设置为 1

    ¥setting the NODE_NO_WARNINGS environment variable to 1

  • --no-warnings 标志传递给节点进程

    ¥passing the --no-warnings flag to the node process

  • NODE_OPTIONS 环境变量中设置 'no-warnings'

    ¥setting 'no-warnings' in the NODE_OPTIONS environment variable

有关如何禁用警告的更多信息,请参阅 node 的文档

¥For more information on how to disable warnings, see node's documentation.

但是,不建议禁用警告,因为这可能会在升级 Fastify 版本时导致潜在问题。只有经验丰富的用户才应考虑禁用警告。

¥However, disabling warnings is not recommended as it may cause potential problems when upgrading Fastify versions. Only experienced users should consider disabling warnings.

Fastify 警告代码

¥Fastify Warning Codes

代码描述怎么解决讨论
FSTWRN001缺少指定的路由架构。这可能表明架构未明确指定。检查路由的架构。#4647
FSTWRN002正在注册的 %s 插件混合了异步和回调样式,这将导致 fastify@5 中的错误。不要混合异步和回调风格。#5139

Fastify 弃用代码

¥Fastify Deprecation Codes

Node.js CLI 选项进一步支持弃用代码:

¥Deprecation codes are further supported by the Node.js CLI options:

代码描述怎么解决讨论