Skip to content

Troubleshooting ​

Routes ​

SymptomCause
A route answers 404The file isn't named <name>.endpoint.ts or endpoint.ts; or it doesn't export default its endpoint; or it sits in a folder owned by a nested router.module.ts you didn't expect.
A new endpoint answers 404An endpoint file is served after a restart. nest start --watch restarts by itself; with node --watch, set watch: true in NestjsEndpoints.forRoot. See Development. A built app serves the endpoint files that are in its build: build again.
A route is mounted at /dist/… or /src/…An endpoint registered by hand has no path. See Explicit paths.
Routes disappear in productionThe build bundles the app into one file. File-based routing needs each file on disk.
middleware options object must be the last entryThe { exclude } object isn't the last entry of a router's middleware.

Requests and responses ​

SymptomCause
400 "Validation failed" on search or path parametersquery and params values arrive as strings. Use z.coerce.number(), z.stringbool() or z.coerce.date().
400 Body cannot be empty when content-type is set to 'application/json', on FastifyA request with Content-Type: application/json and no body. Send {}, or leave the header off.
a GET endpoint cannot declare `input` at startupAn endpoint with method: 'get' declares input. A GET has no body: use query, or drop method.
A long type error on handler: Type '(…) => …' is not assignable to type 'HandlerMethod<…>'The handler's return value doesn't match output. The last line of the message names the field. See In a block body.
500 on a response that looks rightThe return value doesn't match output (ZodSerializationException).
Did not find schema for status code Nresponse(N, …) with a status that output doesn't declare.
A handler returns a value, and nothing validates itoutput has a schema per status, which requires response(status, body).
A response's schema is {} or wrong, in the generated client or an OpenAPI documentA .transform() in the output schema. Use .overwrite(), or .meta({ type }). See Transforms in output schemas.

Setup ​

SymptomCause
this app has N routers and no root when the app startsThe app imports several routers and none is the root. Add NestjsEndpoints.forRoot to the app module; the other routers stay as EndpointRouterModule.create().
NestjsEndpoints.forRoot() is called more than onceAn app calls forRoot once, in its root module. Make every other router with EndpointRouterModule.create().
Vitest must process this package to load endpoint files. Add it to "server.deps.inline" in your Vitest config, in a test runThe Vitest config the run uses doesn't inline the package. Add the setting to each of your Vitest configs.

Routers and injections ​

SymptomCause
Cannot access 'router' before initialization when the app loads. Under Vitest, Cannot read properties of undefined (reading 'endpoint'), or 'query' or 'mutation'An import cycle: the router module statically imports a file that imports its endpoint, directly or through a provider, a guard or a listed endpoint. Move what the router module needs out of that file, or list the endpoint with an endpoints callback.
`endpoints` lists a module that exports no endpointAn import() in a router's endpoints callback points at a module with no endpoint export. Point it at the endpoint's file.
<endpoint file> is built with the endpoint of <router A> but is owned by <router B>The endpoint is built with another router's endpoint. Build it with the endpoint of the router that owns it.
`x` is already injected by its routerThe endpoint declares a key its router's endpointConfig already provides. Remove it from the endpoint.
`x` is in both inject and injectOnRequestA router's endpointConfig declares the key in both maps. Keep it in one.

Generated clients ​

SymptomCause
Nothing is regenerated after an endpoint changesCodegen isn't running; or the route isn't in that client, because it is a plain controller's, or in a namespace the client's namespaces leaves out. forceGenerate: true regenerates every client.
Two operations resolve to the same wrapper propertyTwo operations have the same name in the same namespace. Rename an endpoint file, or a namespace. See How names are derived.
An operation keeps its full name inside its namespace, such as client.shop.recipes.shopRecipesA bare endpoint.ts whose URL is the namespace itself. Give the file a name of its own.
useApiClient must be used within an <ApiClientProvider>No <ApiClientProvider> above the component.
Type errors about XMLHttpRequest or BodyInit in a generated clientThe project compiles without the dom lib. Add it: "lib": ["esnext", "dom"].

Released under the MIT License.