BabylonJS/Babylon.js · error · Error
`Uniforms must have a name: '${uniformLine}'`
Error message
`Uniforms must have a name: '${uniformLine}'` What it means
Symmetric to the type check: the regex matched but the name capture group is empty, so the uniform has a type but no recognizable name. The tool cannot create a named uniform/connection point without it.
Source
Thrown at packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts:148
const annotationJSON = matches[1];
const uniformLine = matches[2];
if (!uniformLine) {
throw new Error("Uniform line not found");
}
const uniformLineMatches = new RegExp(/^uniform\s+(\w+)\s+(\w+)\s*;?/gm).exec(uniformLine);
if (!uniformLineMatches || uniformLineMatches.length < 3) {
throw new Error(`Uniforms must have a type and a name: '${uniformLine}'`);
}
const uniformTypeString = uniformLineMatches[1];
const uniformName = uniformLineMatches[2];
if (!uniformTypeString) {
throw new Error(`Uniforms must have a type: '${uniformLine}'`);
}
if (!uniformName) {
throw new Error(`Uniforms must have a name: '${uniformLine}'`);
}
// Convert to ConnectionPointType
let type: ConnectionPointType;
switch (uniformTypeString) {
case "float":
type = ConnectionPointType.Float;
break;
case "sampler2D":
type = ConnectionPointType.Texture;
break;
case "vec3":
type = ConnectionPointType.Color3;
break;
case "vec4":
type = ConnectionPointType.Color4;
break;
case "bool":
View on GitHub (pinned to 0592b347b8)
Solutions
- Add an identifier name to the uniform declaration.
- Verify each uniform line follows 'uniform <type> <name>;' exactly.
- Check the echoed line in the error message to locate the broken statement.
Example fix
// before uniform float; // after uniform float opacity;
Defensive patterns
Strategy: validation
Validate before calling
src.split('\n').forEach((l, i) => { const m = l.trim().match(/^uniform\s+(\w+)\s+(\w+)\s*;?$/); if (l.trim().startsWith('uniform') && (!m || !m[2])) console.error(`Uniform missing name at line ${i+1}`); }); Try / catch
try { await ConvertShader(path, ...); } catch (e) { const m = e.message.match(/Uniforms must have a name: '(.*)'/); if (m) { addUniformName(m[1]); } else { throw e; } } Prevention
- Always name every uniform.
- Avoid half-finished declarations in committed shaders.
- Review shader diffs for dropped identifiers.
When it happens
Trigger: A declaration like 'uniform float;' or trailing characters that stop the (\w+) name capture from matching.
Common situations: Incomplete declarations after editing; accidentally deleting a uniform's name; template generation bugs producing nameless uniforms.
Related errors
- `Uniforms must have a type and a name: '${uniformLine}'`
- `Uniforms must have a type: '${uniformLine}'`
- "Uniform line not found"
- `Unsupported uniform type: '${uniformTypeString}'`
- `Consts must have a name, type, and a default value: '${cons
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/87b765b4e2afd5fe.
Report an issue: GitHub.