Fastify 中文文档 (v4.28.1)

Table of contents

Warnings

Warnings In Fastify

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:

  • setting the NODE_NO_WARNINGS environment variable to 1
  • passing the --no-warnings flag to the node process
  • setting 'no-warnings' in the NODE_OPTIONS environment variable

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

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

Fastify Warning Codes

CodeDescriptionHow to solveDiscussion
FSTWRN001The specified schema for a route is missing. This may indicate the schema is not well specified.Check the schema for the route.#4647
FSTWRN002The %s plugin being registered mixes async and callback styles, which will result in an error in fastify@5.Do not mix async and callback style.#5139

Fastify Deprecation Codes

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

CodeDescriptionHow to solveDiscussion
FSTDEP005You are accessing the deprecated request.connection property.Use request.socket.#2594
FSTDEP006You are decorating Request/Reply with a reference type. This reference is shared amongst all requests.Do not use Arrays/Objects as values when decorating Request/Reply.#2688
FSTDEP007You are trying to set a HEAD route using exposeHeadRoute route flag when a sibling route is already set.Remove exposeHeadRoutes or explicitly set exposeHeadRoutes to false#2700
FSTDEP008You are using route constraints via the route {version: "..."} option.Use {constraints: {version: "..."}} option.#2682
FSTDEP009You are using a custom route versioning strategy via the server {versioning: "..."} option.Use {constraints: {version: "..."}} option.#2682
FSTDEP010Modifying the reply.sent property is deprecated.Use the reply.hijack() method.#3140
FSTDEP011Variadic listen method is deprecated.Use .listen(optionsObject).#3712
FSTDEP012You are trying to access the deprecated request.context property.Use request.routeOptions.config or request.routeOptions.schema.#4216 #5084
FSTDEP013Direct return of "trailers" function is deprecated.Use "callback" or "async-await" for return value.#4380
FSTDEP014You are trying to set/access the default route. This property is deprecated.Use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.#4480
FSTDEP015You are accessing the deprecated request.routeSchema property.Use request.routeOptions.schema.#4470
FSTDEP016You are accessing the deprecated request.routeConfig property.Use request.routeOptions.config.#4470
FSTDEP017You are accessing the deprecated request.routerPath property.Use request.routeOptions.url.#4470
FSTDEP018You are accessing the deprecated request.routerMethod property.Use request.routeOptions.method.#4470
FSTDEP019You are accessing the deprecated reply.context property.Use reply.routeOptions.config or reply.routeOptions.schema.#5032 #5084
FSTDEP020You are using the deprecated reply.getReponseTime() method.Use the reply.elapsedTime property instead.#5263
FSTDEP021The reply.redirect() method has a new signature: reply.redirect(url: string, code?: number). It will be enforced in fastify@v5'.#5483