WebGL GLSL ” : syntax error

2 minute read.

GL::Shader::compile(): compilation of fragment shader 2 failed with the following message:
ERROR: 1:1: '' : syntax error

Aparent­ly We­bGL shad­er com­pil­ers some­times just de­ny you any in­for­ma­tion on what’s wrong with your shad­er code.

Potential Causes

To hope­ful­ly save some peo­ple some time, here are the code snip­pets that I know can cause this er­ror:

Preprocessor Multiplication

#define A 1
#define B 2

uniform lowp vec4 array[A*B];

#ifdef NOT_DEFINED_SYMBOL
// Not a problem if not evaluated
uniform lowp vec4 array2[A*B];
#endif

Includes

#ifdef NOT_DEFINED_SYMBOL
#include "Someother.glsl"
#endif

Yes, in­cludes are not sup­port­ed in GLSL, but if you have your own sys­tem for that, make sure you don’t leave any traces of that. Even when it should not be eval­u­at­ed, it may cause the above is­sue.