I’ve been experimenting with using ES6 modules with my babylonjs application, and discovered that if you include the inspector, it only works when you use webpack to package the application.
If instead you use something like es-dev-server to serve up the modules in a development environment, you get an error:
universalModuleDefinition:9 Uncaught TypeError: Cannot read property 'GUI' of undefined
at webpackUniversalModuleDefinition (universalModuleDefinition:9)
at universalModuleDefinition:10
All you need to do to recreate the bug is something as simple as:
import { Engine } from "@babylonjs/core/Engine/engine";
import { Scene } from "@babylonjs/core/scene";
import { Color3, Color4, MeshBuilder, DirectionalLight } from '@babylonjs/core';
import { Vector3 } from '@babylonjs/core/Maths/math';
import "@babylonjs/core/Meshes/meshBuilder";
import "@babylonjs/inspector"; // this is the line which causes problems, even if we don't use it.
let engine = new Engine(c,true);
let scene = new Scene(engine);
scene.clearColor = new Color4(0.02, 0.02, 0.02, 1);
scene.blockMaterialDirtyMechanism = true;
let VRHelper = scene.createDefaultVRExperience({ rayLength: 1000, laserToggle: false, useMultiview: false });
VRHelper.enableInteractions();
scene.activeCamera.maxZ = 1E8;
VRHelper.onAfterEnteringVRObservable.add(() => {
scene.activeCamera.maxZ = 1E8;
VRHelper.changeLaserColor(new Color3(0.5, 0.1, 0.1));
});
var light = new DirectionalLight("DirectionalLight", new Vector3(0, -1, 0), scene);
light.diffuse = new Color3(1, 0, 0);
light.specular = new Color3(0, 1, 0);
var sphere = MeshBuilder.CreateSphere("sphere", {}, scene);
engine.runRenderLoop(function() {
scene.render();
});
If you remove the reference to the inspector, all is fine.
Adding in a reference to the GUI module doesn’t seem to help.