BabylonJS/Babylon.js · error · Error
`Uniforms must have a type: '${uniformLine}'`
Error message
`Uniforms must have a type: '${uniformLine}'` What it means
The uniform regex matched, but the type capture group is empty — the declaration has a name but no recognizable type word. The tool needs the type to map to a ConnectionPointType, so it throws with the offending line.
Source
Thrown at packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts:145
const uniformRegExp = new RegExp(/(\/\/\s*\{.*\}\s*(?:\r\n|\r|\n)+)?(uniform .*)/gm);
const uniformGroups = fragmentShader.matchAll(uniformRegExp);
for (const matches of uniformGroups) {
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":
View on GitHub (pinned to 0592b347b8)
Solutions
- Ensure the uniform line includes an explicit concrete GLSL type (float, vec2, etc.).
- Avoid macros/typedefs in uniform type positions; inline the concrete type.
- Inspect the line echoed in the error message and fix the declaration.
Example fix
// before uniform textureSize; // after uniform vec2 textureSize;
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[1])) console.error(`Uniform missing type at line ${i+1}`); }); Try / catch
try { await ConvertShader(path, ...); } catch (e) { const m = e.message.match(/Uniforms must have a type: '(.*)'/); if (m) { addConcreteType(m[1]); } else { throw e; } } Prevention
- Use concrete GLSL types (float, vec2, ...) not macros in uniform declarations.
- Never leave a uniform declaration incomplete.
- Review shader edits for deleted type tokens.
When it happens
Trigger: A uniform declaration like 'uniform someName;' or whitespace/formatting that prevents the (\w+) type capture from matching.
Common situations: Corrupted or partially deleted uniform lines; macro-based types that the regex cannot capture (e.g. uniform PRECISION float x) resolved differently at parse time.
Related errors
- `Uniforms must have a type and a name: '${uniformLine}'`
- `Uniforms must have a name: '${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/648850ea01916284.
Report an issue: GitHub.