{"id":"5e29405210b0403a","repo":"nestjs/nest","slug":"version-constraint-should-be-a-string-or-an-array","errorCode":null,"errorMessage":"Version constraint should be a string or an array of strings.","messagePattern":"Version constraint should be a string or an array of strings\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/platform-fastify/adapters/fastify-adapter.ts","lineNumber":165,"sourceCode":"  private _isParserRegistered: boolean;\n  private onRequestHook?: (\n    request: TRequest,\n    reply: TReply,\n    done: (err?: Error) => void,\n  ) => void | Promise<void>;\n  private onResponseHook?: (\n    request: TRequest,\n    reply: TReply,\n    done: (err?: Error) => void,\n  ) => void | Promise<void>;\n  private isMiddieRegistered: boolean;\n  private pendingMiddlewares: Array<{ args: any[] }> = [];\n  private versioningOptions?: VersioningOptions;\n  private readonly versionConstraint = {\n    name: 'version',\n    validate(value: unknown) {\n      if (!isString(value) && !Array.isArray(value)) {\n        throw new Error(\n          'Version constraint should be a string or an array of strings.',\n        );\n      }\n    },\n    storage() {\n      const versions = new Map<string, unknown>();\n      return {\n        get(version: string | Array<string>) {\n          if (Array.isArray(version)) {\n            return versions.get(version.find(v => versions.has(v))!) || null;\n          }\n          return versions.get(version) || null;\n        },\n        set(versionOrVersions: string | Array<string>, store: unknown) {\n          const storeVersionConstraint = (version: string) =>\n            versions.set(version, store);\n          if (Array.isArray(versionOrVersions))\n            versionOrVersions.forEach(storeVersionConstraint);","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/platform-fastify/adapters/fastify-adapter.ts#L147-L183","documentation":"Error \"Version constraint should be a string or an array of strings.\" thrown in nestjs/nest.","triggerScenarios":"Thrown at packages/platform-fastify/adapters/fastify-adapter.ts:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the route/controller version to a string (e.g. '1') or an array of strings (e.g. ['1','2']).","Do not pass numbers, objects, or undefined as the version constraint.","Use VERSION_NEUTRAL explicitly when a route should ignore versioning."],"exampleFix":"@Controller({ path: 'cats', version: ['1', '2'] })\nexport class CatsController {}","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}