ES6 can't find MergeMeshes module

I’m trying to use this in ES6 as a module from @babylonjs/core;
var mesh = BABYLON.Mesh.MergeMeshes([sphere, cube, ground]);

but can’t seem to find the module?

Usage of this function is in this sandbox(line 152)

Any idea how to apprach this? Thanks :slight_smile:

It looks like you have used the legacy export and then that should work. Otherwise you can just import Mesh directly and use the method - it is declared static on the Mesh object. Importing directly will help with tree shaking and is probably the recommended way to go.

Sorry I think my question was abit unclear, I was trying to find the MergeMeshes function from @babylonjs/core so that I could import it as a ES6 module but could not find it.

So I ended up using;
import * as BABYLON from “@babylonjs/core/Legacy/legacy”

is there a better way?

no, it was my answer that could have used more clarity. you did the import correctly for the legacy import and that looks to me like it should work. The “correct” way in my opinion though is to import directly when using ES6. ie:

import { Mesh } from '@babylonjs/core/Meshes/mesh'

// then call static method directly
const mergedMeshes: Nullable<Mesh> = Mesh.MergeMeshes([sphere, cube, ground]);

You will probably be missing some side-effect imports. Those are here:
Babylon.js ES6 support with Tree Shaking | Babylon.js Documentation (


Thanks a bunch, just what I was looking for :slight_smile:

1 Like