skip to Main Content

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


  1. Chosen as BEST ANSWER

    It was apparently a JSON Schema issue.

    In one of the routes, I had the schema like this,

    {
      type: "object",
      required: ["fileType"],
      properties: {
        fileType: {
          type: {
             type: "string",
             enum: ["a", "b", "c", "d", "all"]
          }
        }
      }
    }
    

    Which is wrong, and it should be,

    {
      type: "object",
      required: ["fileType"],
      properties: {
        fileType: {
          type: "string",
          enum: ["a", "b", "c", "d", "all"]
        }
      }
    }
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search