TerrainMaterial not a construtor using webpack

Hi guys,

I have strange issue with a small project I’m working on. I’m using webpack to bundle up my code when I try to run my build on the browser I get this error:

babylonjs__WEBPACK_IMPORTED_MODULE_0__.TerrainMaterial is not a constructor

I installed the babylonjs-materials package from npm and I’m importing it in my file, however the error persists. Any ideas as to what could be causing this issue? I’m fairly new to webpack it’s possible I’m doing something wrong there but any help would be greatly appreciated.

Okay after some digging through Babylon’s NPM docs I learned that the proper way to import the babylon-materials packapge is using:

import * as Materials from 'babylonjs-materials';

and not

import 'babylonjs-materials';

as the NPM site suggests, I’m not sure why it this does not extend the BABYLON namespace, but either way the docs say otherwise.

links for verification:


https://doc.babylonjs.com/features/npm_support#installing-other-babylon-modules

I think the info in the NPM site should be fixed as the BABYLON docs are very specific that when using es6 modules you have to set your own namespace.

I hope this helps others, happy hacking!

1 Like