BabylonJS/Babylon.js · error
Could not find a blockType
Error message
Could not find a blockType
What it means
importCustomBlockDefinition validates a serialized custom block definition and requires a blockType that identifies the block in the registry. The only inference performed is using the definition's name when format is "smartFilter"; for any other format (e.g. GLSL annotated shaders, where blockType comes from parsing the shader), a missing blockType is a hard validation failure.
Source
Thrown at packages/dev/smartFilters/src/serialization/importCustomBlockDefinition.ts:41
return ImportAnnotatedGlsl(serializedData);
} else {
// Assume this is a serialized JSON object
const blockDefinition = JSON.parse(serializedData);
// Some old SmartFilters didn't have a format property - default to smartFilter if missing
if (blockDefinition.format === undefined) {
blockDefinition.format = "smartFilter";
}
// SmartFilters can be serialized without a blockType
// By convention, we use the SmartFilter name as the blockType when importing them as SerializedBlockDefinitions
if (blockDefinition.format === "smartFilter" && blockDefinition.name && !blockDefinition.blockType) {
blockDefinition.blockType = blockDefinition.name;
}
// Validation
if (!blockDefinition.blockType) {
throw new Error("Could not find a blockType");
}
return blockDefinition;
}
}
/**
* Converts a fragment shader .glsl file to an SerializedBlockDefinition instance for use
* as a CustomShaderBlock. The .glsl file must contain certain annotations to be imported.
* See readme.md for more information.
* @param fragmentShader - The contents of the .glsl fragment shader file
* @returns The serialized block definition
*/
function ImportAnnotatedGlsl(fragmentShader: string): SerializedShaderBlockDefinition {
setLogger(Logger);
const fragmentShaderInfo = ParseFragmentShader(fragmentShader);
if (!fragmentShaderInfo.blockType) {
View on GitHub (pinned to 0592b347b8)
Solutions
- Add a blockType field to the serialized block definition JSON.
- If format is "smartFilter", ensure name is set so it can be inferred as blockType.
- If the definition is GLSL-based, include the blockType annotation in the shader source so parsing yields it.
- Validate the definition shape before import (see defense validationCode).
- Re-export from the tooling version that emits blockType if working with legacy files.
Example fix
// before
const def = { name: "MyBlock", format: "smartFilter" }; // blockType missing, ok only via name
const def2 = { format: "glsl" }; // throws
// after
const def2 = { blockType: "MyBlock", format: "glsl" }; Defensive patterns
Strategy: validation
Validate before calling
function validateBlockDefinition(def) {
const hasType = !!def.blockType || (def.format === "smartFilter" && !!def.name);
if (!hasType) throw new Error("Block definition needs blockType (or name when format is smartFilter)");
return def;
} Type guard
function hasBlockType(d) {
return typeof d === "object" && d !== null &&
(typeof d.blockType === "string" && d.blockType.length > 0 ||
(d.format === "smartFilter" && typeof d.name === "string" && d.name.length > 0));
} Try / catch
try {
const def = ImportCustomBlockDefinition(rawDef);
} catch (e) {
if (e.message === "Could not find a blockType") {
throw new Error(`Definition '${rawDef?.name ?? "?"}' is missing blockType — fix the JSON before import`);
}
throw e;
} Prevention
- Always include blockType in serialized custom block definitions.
- For smartFilter-format definitions, ensure name is present so it can serve as blockType.
- For GLSL definitions, keep the blockType annotation in the shader source.
- Schema-validate exported filter JSON before import.
- Regenerate legacy definitions with the current tooling version.
When it happens
Trigger: Calling ImportCustomBlockDefinition with a definition whose blockType is undefined/null and either format is not "smartFilter" or name is also missing/empty — e.g. hand-written JSON missing the blockType field, or an annotated-GLSL definition (format "glsl") whose shader never got blockType set.
Common situations: Copying a block definition between filters and dropping required fields, authoring custom block JSON by hand, schema version drift where older exports lacked blockType, or GLSL shaders parsed without a blockType annotation.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- blockType must be defined
- `No serializer was provided for a block of type ${block.bloc
- Was asked to serialize an unrecognized block type
- Source block ${connection.outputBlock} not found
- `Target block ${connection.inputBlock} not found`
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/eb40efbcbf1b0a42.
Report an issue: GitHub.