Node.js 警告的名称


Node.js 触发的警告类型(由 name 属性标识)没有严格的指导方针。 可以随时添加新类型的警告。 一些最常见的警告类型包括:

  • 'DeprecationWarning' - 表示使用已弃用的 Node.js API 或功能。 此类警告必须包含标识弃用代码'code' 属性。
  • 'ExperimentalWarning' - 表示使用实验的 Node.js API 或功能。 必须谨慎使用此类功能,因为它们可能随时更改,并且不受与受支持功能相同的严格语义版本控制和长期支持政策的约束。
  • 'MaxListenersExceededWarning' - 表示在 EventEmitterEventTarget 上注册了太多给定事件的监听器。 这通常表示内存泄漏。
  • 'TimeoutOverflowWarning' - 表示已向 setTimeout()setInterval() 函数提供了无法容纳在 32 位有符号整数内的数值。
  • 'UnsupportedWarning' - 表示使用不受支持的选项或功能,这些选项或功能将被忽略而不是被视为错误。 一个示例是在使用 HTTP/2 兼容性 API 时使用 HTTP 响应状态消息。

There are no strict guidelines for warning types (as identified by the name property) emitted by Node.js. New types of warnings can be added at any time. A few of the warning types that are most common include:

  • 'DeprecationWarning' - Indicates use of a deprecated Node.js API or feature. Such warnings must include a 'code' property identifying the deprecation code.
  • 'ExperimentalWarning' - Indicates use of an experimental Node.js API or feature. Such features must be used with caution as they may change at any time and are not subject to the same strict semantic-versioning and long-term support policies as supported features.
  • 'MaxListenersExceededWarning' - Indicates that too many listeners for a given event have been registered on either an EventEmitter or EventTarget. This is often an indication of a memory leak.
  • 'TimeoutOverflowWarning' - Indicates that a numeric value that cannot fit within a 32-bit signed integer has been provided to either the setTimeout() or setInterval() functions.
  • 'UnsupportedWarning' - Indicates use of an unsupported option or feature that will be ignored rather than treated as an error. One example is use of the HTTP response status message when using the HTTP/2 compatibility API.