BabylonJS/Babylon.js · error · Error

`Consts must have a name: '${constLine}'`

Error message

`Consts must have a name: '${constLine}'`

What it means

The regex for the const line captured a type and optional value but the friendly-name capture group (\w+) is empty. Since (\w+) cannot normally match empty, reaching this check usually indicates the const line was matched by an odd path or the captured name failed a truthiness check after decoration-adjacent processing. It guards that every exposed property const has an identifier name.

Source

Thrown at packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts:222

            continue;
        }

        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}'`);

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Give the const a valid GLSL identifier name: `const float exposure = 1.0;`.
  2. Verify no macro/minifier step removed identifiers before conversion.
  3. Check the const line for typos such as double spaces collapsing the name or a stray `=`.

Example fix

// before
const float  = 0.5;
// after
const float exposure = 0.5;
Defensive patterns

Strategy: validation

Validate before calling

if ([...shader.matchAll(/const\s+\w+\s+(?=\s*=)/g)].length) throw new Error("Property const missing a variable name");

Type guard

function constHasName(line: string): boolean {
  const m = /^const\s+\w+\s+(\w+)\s*=/.exec(line);
  return !!m && !!m[1];
}

Try / catch

try {
  const info = ParseFragmentShader(blockName, namespace, shader);
} catch (e) {
  if (e instanceof Error && e.message.startsWith("Consts must have a name")) {
    // repair: give the const an identifier before retrying
  } else throw e;
}

Prevention

When it happens

Trigger: ParseFragmentShader on a const line where the name token is absent or not a word character, e.g. `const float = 0.5;` (missing identifier), or a shader where preprocessing stripped identifiers.

Common situations: Accidentally deleted variable name while editing a shader; code generators emitting placeholder consts with blank names; IDE refactor that removed a name.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/a54e31cc5d25e33e. Report an issue: GitHub.