When i created a new API with fastify, while testing it, it was throwing
TypeError: Cannot read property 'length' of undefined
at next (node_modules/fastify/lib/route.js:407:32)
at preParsingHookRunner (node_modules/fastify/lib/route.js:438:3)
at runPreParsing (node_modules/fastify/lib/route.js:389:5)
at Object.routeHandler [as handler] (node_modules/fastify/lib/route.js:349:7)
at Router.lookup (node_modules/find-my-way/index.js:356:14)
The control doesn’t even pass to the routes and when i checked the file mentioned in the stack trace, it seems to be related with preParser
2
Answers
It was apparently a JSON Schema issue.
In one of the routes, I had the schema like this,
Which is wrong, and it should be,
The error message specifically indicates that the property length is being called on an undefined value. This could be due to an issue with the data being passed to the preParsing hook, or a problem with the code inside the hook itself.