discordjs/discord.js · error · Error

Cannot properly serialize component type: ${data.type}

Error message

Cannot properly serialize component type: ${data.type}

What it means

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.

Source

Thrown at packages/builders/src/components/Components.ts:242

		case ComponentType.File:
			return new FileBuilder(data);
		case ComponentType.Separator:
			return new SeparatorBuilder(data);
		case ComponentType.TextDisplay:
			return new TextDisplayBuilder(data);
		case ComponentType.MediaGallery:
			return new MediaGalleryBuilder(data);
		case ComponentType.Section:
			return new SectionBuilder(data);
		case ComponentType.Container:
			return new ContainerBuilder(data);
		case ComponentType.Label:
			return new LabelBuilder(data);
		case ComponentType.FileUpload:
			return new FileUploadBuilder(data);
		default:
			// TODO: add back @ts-expect-error This case can still occur if we get a newer unsupported component type
			throw new Error(`Cannot properly serialize component type: ${data.type}`);
	}
}

function createButtonBuilder(data: APIButtonComponent): ButtonBuilder {
	switch (data.style) {
		case ButtonStyle.Primary:
			return new PrimaryButtonBuilder(data);
		case ButtonStyle.Secondary:
			return new SecondaryButtonBuilder(data);
		case ButtonStyle.Success:
			return new SuccessButtonBuilder(data);
		case ButtonStyle.Danger:
			return new DangerButtonBuilder(data);
		case ButtonStyle.Link:
			return new LinkButtonBuilder(data);
		case ButtonStyle.Premium:
			return new PremiumButtonBuilder(data);
		default:

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Update @discordjs/builders (and discord.js) to the latest version so the new component type is supported.
  2. Filter or skip unknown component types before passing data to createComponentBuilder.
  3. If the data is hand-written, correct the `type` field to a valid ComponentType enum value.
  4. If pinned, unpin versions so a library update can bring the new component support.

Example fix

// before
const builder = createComponentBuilder(rawComponent); // rawComponent.type = 99 (unsupported)
// after
if (rawComponent.type in ComponentType) {
  const builder = createComponentBuilder(rawComponent);
} // or upgrade the library for support
Defensive patterns

Strategy: type-guard

Validate before calling

const supportedTypes = new Set(Object.values(ComponentType));
if (!supportedTypes.has(data.type)) {
  console.warn('Skipping unsupported component type', data.type);
}

Type guard

function isSupportedComponent(t: number): t is ComponentType {
  return Object.values(ComponentType).includes(t as ComponentType);
}

Try / catch

try {
  const builder = createComponentBuilder(data);
} catch (err) {
  if ((err as Error).message.startsWith('Cannot properly serialize component type')) {
    console.warn('Unsupported component type; upgrade the library or skip this component.');
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30). Data as JSON: /api/errors/623301cd406fb387. Report an issue: GitHub.