{"record":{"id":"623301cd406fb387","repo":"discordjs/discord.js","slug":"cannot-properly-serialize-component-type-data-t","errorCode":null,"errorMessage":"Cannot properly serialize component type: ${data.type}","messagePattern":"Cannot properly serialize component type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/builders/src/components/Components.ts","lineNumber":242,"sourceCode":"\t\tcase ComponentType.File:\n\t\t\treturn new FileBuilder(data);\n\t\tcase ComponentType.Separator:\n\t\t\treturn new SeparatorBuilder(data);\n\t\tcase ComponentType.TextDisplay:\n\t\t\treturn new TextDisplayBuilder(data);\n\t\tcase ComponentType.MediaGallery:\n\t\t\treturn new MediaGalleryBuilder(data);\n\t\tcase ComponentType.Section:\n\t\t\treturn new SectionBuilder(data);\n\t\tcase ComponentType.Container:\n\t\t\treturn new ContainerBuilder(data);\n\t\tcase ComponentType.Label:\n\t\t\treturn new LabelBuilder(data);\n\t\tcase ComponentType.FileUpload:\n\t\t\treturn new FileUploadBuilder(data);\n\t\tdefault:\n\t\t\t// TODO: add back @ts-expect-error This case can still occur if we get a newer unsupported component type\n\t\t\tthrow new Error(`Cannot properly serialize component type: ${data.type}`);\n\t}\n}\n\nfunction createButtonBuilder(data: APIButtonComponent): ButtonBuilder {\n\tswitch (data.style) {\n\t\tcase ButtonStyle.Primary:\n\t\t\treturn new PrimaryButtonBuilder(data);\n\t\tcase ButtonStyle.Secondary:\n\t\t\treturn new SecondaryButtonBuilder(data);\n\t\tcase ButtonStyle.Success:\n\t\t\treturn new SuccessButtonBuilder(data);\n\t\tcase ButtonStyle.Danger:\n\t\t\treturn new DangerButtonBuilder(data);\n\t\tcase ButtonStyle.Link:\n\t\t\treturn new LinkButtonBuilder(data);\n\t\tcase ButtonStyle.Premium:\n\t\t\treturn new PremiumButtonBuilder(data);\n\t\tdefault:","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/builders/src/components/Components.ts#L224-L260","documentation":"createComponentBuilder maps an incoming API component's `type` to the matching builder class. The switch covers all component types the library supports; the default branch throws when it receives a component type value it does not know — typically a component type added in a newer Discord API version than this library version supports.","triggerScenarios":"Calling createComponentBuilder (via component resolution in builders/constructors or resolved payloads) with data whose `data.type` is an unknown ComponentType value — e.g. a raw API component from an interaction payload using a newer component type, or a corrupted/fabricated type value.","commonSituations":"Discord adds a new component type and the cached library version predates support; bots built from raw API data (e.g. from webhooks or forwarded messages) containing unsupported components; hand-crafted JSON with a wrong numeric type.","solutions":["Update @discordjs/builders (and discord.js) to the latest version so the new component type is supported.","Filter or skip unknown component types before passing data to createComponentBuilder.","If the data is hand-written, correct the `type` field to a valid ComponentType enum value.","If pinned, unpin versions so a library update can bring the new component support."],"exampleFix":"// before\nconst builder = createComponentBuilder(rawComponent); // rawComponent.type = 99 (unsupported)\n// after\nif (rawComponent.type in ComponentType) {\n  const builder = createComponentBuilder(rawComponent);\n} // or upgrade the library for support","handlingStrategy":"type-guard","validationCode":"const supportedTypes = new Set(Object.values(ComponentType));\nif (!supportedTypes.has(data.type)) {\n  console.warn('Skipping unsupported component type', data.type);\n}","typeGuard":"function isSupportedComponent(t: number): t is ComponentType {\n  return Object.values(ComponentType).includes(t as ComponentType);\n}","tryCatchPattern":"try {\n  const builder = createComponentBuilder(data);\n} catch (err) {\n  if ((err as Error).message.startsWith('Cannot properly serialize component type')) {\n    console.warn('Unsupported component type; upgrade the library or skip this component.');\n  } else throw err;\n}","preventionTips":["Keep @discordjs/builders and discord.js up to date.","Sanitize raw API payloads before building components.","Never hardcode numeric component types; use the ComponentType enum."],"tags":["components","serialization","unsupported-type"],"backgroundTag":"unsupported-component-type","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}