BabylonJS/Babylon.js · error · Error
`Consts must have a value: '${constLine}'`
Error message
`Consts must have a value: '${constLine}'` What it means
The parsed const line has a name but the default-value capture is null. Property consts must carry a default value because it becomes the initial value of the generated Smart Filter property. This is the 'value missing' variant of the const validation errors.
Source
Thrown at packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts:225
const constLine = matches[2];
if (!constLine) {
throw new Error("Const line not found");
}
const constLineMatches = new RegExp(/^const\s+(\w+)\s+(\w+)\s*=\s*([^\s;]+)\s*;?\s*$/gm).exec(constLine);
if (!constLineMatches || constLineMatches.length < 4) {
throw new Error(`Consts must have a name, type, and a default value: '${constLine}'`);
}
const type = constLineMatches[1];
const friendlyName = constLineMatches[2];
const defaultValue = constLineMatches[3];
if (!friendlyName) {
throw new Error(`Consts must have a name: '${constLine}'`);
}
if (defaultValue === null) {
throw new Error(`Consts must have a value: '${constLine}'`);
}
const constProperty: ConstPropertyMetadata | null =
type === "float"
? {
name: DecorateSymbol(friendlyName),
friendlyName,
type,
defaultValue: parseFloat(defaultValue),
options: annotation.property.options as ConstMetadataAnnotationFloatOptions | undefined,
}
: null;
if (!constProperty) {
throw new Error(`Unsupported const property type: '${type}'`);
}
fragmentConstProperties.push(constProperty);
View on GitHub (pinned to 0592b347b8)
Solutions
- Add a default value to the const: `const float exposure = 1.0;`.
- If no default is desired, remove the {"property":...} annotation so the const is treated as ordinary.
- Set the default via the annotation's property options if a specific initial value is needed (the defaultValue still must be syntactically present).
Example fix
// before
// {"property": {"type": "float"}}
const float exposure;
// after
// {"property": {"type": "float"}}
const float exposure = 1.0; Defensive patterns
Strategy: validation
Validate before calling
if (/const\s+\w+\s+\w+\s*;/.test(shader)) throw new Error("Property consts must declare a default value"); Type guard
function constHasValue(line: string): boolean {
const m = /^const\s+\w+\s+\w+\s*=\s*([^\s;]+)/.exec(line);
return !!m && m[1] !== null && m[1].length > 0;
} Try / catch
try {
const info = ParseFragmentShader(blockName, namespace, shader);
} catch (e) {
if (e instanceof Error && e.message.startsWith("Consts must have a value")) {
// add an initializer to the const and retry
} else throw e;
} Prevention
- Always initialize consts at declaration (required by property consts).
- If a const is computed at runtime, use a uniform instead of a const.
- Grep shader assets for `const \w+ \w+;` before building.
When it happens
Trigger: ParseFragmentShader on `const float exposure;` or `const float exposure = ;` — an annotated property const declared without an initializer.
Common situations: Declaring a const intending to assign later (invalid for property consts); refactoring removed the initializer; template-generated shader with a missing value placeholder.
Related errors
- "Const line not found"
- `Consts must have a name, type, and a default value: '${cons
- `Consts must have a name: '${constLine}'`
- `Unsupported const property type: '${type}'`
- "No function name found in shader code"
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/6811fd7ec722a49d.
Report an issue: GitHub.