Fastify - TypeError:无法读取未定义的属性“length”
2023-02-21
932
当我使用 fastify 创建一个新的 API 时,在测试它时,它抛出了
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)
控制甚至没有传递给路由,当我检查堆栈跟踪中提到的文件时,它似乎与 preParser 有关
2个回答
错误消息明确指出,对未定义值调用了属性 length。这可能是由于传递给 preParsing 钩子的数据存在问题,或者钩子本身内部的代码存在问题。
Milan Bhattarai
2023-02-21
这显然是一个 JSON Schema 问题。
在其中一条路线中,我有这样的模式,
{
type: "object",
required: ["fileType"],
properties: {
fileType: {
type: {
type: "string",
enum: ["a", "b", "c", "d", "all"]
}
}
}
}
这是错误的,应该是,
{
type: "object",
required: ["fileType"],
properties: {
fileType: {
type: "string",
enum: ["a", "b", "c", "d", "all"]
}
}
}
Abinash
2023-02-21