How to fix "Error redefinition of a" in ReactJS, ThreeJS and GLSL

Oscar de la Hera Gomez
Two flowers that represent ReactJS and ThreeJS with the text "Redefinition Error in GLSL."

Unlike ReactJS, in GLSL you can only include a file once within an entire program.

A screenshot of the chrome inspector showing an error of redefinition of structs in GLSL.

If you attempt to include (i.e. import) a file into multiple locations within the same shader program (i.e. include the "structs" in the "functionality" and also include the ""structs" and "functionality" in the vertex and fragment shader) it will give a redefinition error.

This is because you can only include a file once within a shader program.

To fix this error restructure your code to centralize shared code so that files are only included ones.

The way we did this is by creating a structs.glsl file that holds all the structs and included the structs.glsl in a functionality.glsl file that holds all the shared functionality. The shaders then included the functionality.glsl - making all the functionality and structs available to the program.

To see open source code that does this, please consult the guide below.

Looking to learn more about ReactJS and ThreeJS ?

Search our blog to find educational content on learning how to use ReactJS and ThreeJS.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details