Load materials library dynamically


I need to load babylon.js source code in a dynamic manner. I’m not sure if I’ll be loading it at all or what version will I be uploading if so. This seems to work fine for me while loading the code from my CDN with a copy of this file for example for version 4.2.1.

This is also the case for loading BabylonJs materials library. Problem is, loading this code throws an error:

cell.fragment.ts:137 Uncaught TypeError: Cannot read properties of undefined (reading 'ShaderStore')
    at Module../cell/cell.fragment.ts (<anonymous>:433:59)
    at __webpack_require__ (<anonymous>:30:30)
    at Module../cell/cellMaterial.ts (<anonymous>:488:72)
    at __webpack_require__ (<anonymous>:30:30)
    at Module../cell/index.ts (<anonymous>:793:71)
    at __webpack_require__ (<anonymous>:30:30)
    at Module../index.ts (<anonymous>:3055:69)
    at __webpack_require__ (<anonymous>:30:30)
    at Module.<anonymous> (<anonymous>:3619:110)
    at Module../legacy/legacy.ts (<anonymous>:3674:30)

Note that self.BABYLON is not undefined when loading this file and runing his code.

Is there a way to use BabylonJs materials library without importing it as a module but dynamically loading it at runtime?


I’ve actually rolled back to the previous version (4.2.0) and it seems to work fine.

Can you share a reproduction of the issue? it shouldn’t happen if you are using the same versions of babylon and the materials library. is it possible you have versions mismatch between the two?

1 Like

Went back to version 4.2.1 but cannot reproduce the issue. Probebly my bad and not related to Babylon.js.

In case that’s not the case I will update here, Apologize for the noise.


Thanks! Please do, we want to be sure it all works as expected.