Error: UniversalCamera needs to be imported before as it contains a side-effect required by your code

Context: I’ve been trying to broadcast a scene from one client to another through socket.io (cf. broadcast scene). I’ve suceeded to do so but after some changes, I’m facing a new error now.

To summarize briefly what I did: A client load a scene in his session, then with the Babylon serializer it’s serialized then converted to a string. After that, the string is broadcasted through socket.io. Once the other client receive the serialized scene I use the SceneLoader append function as:

SceneLoader.Append('', 'data:' + newScene, this.scene, this.updateScene.bind(this), null , this.appendError.bind(this));

And here the appendError is triggered with the following error:
UniversalCamera needs to be imported before as it contains a side-effect required by your code

It seems you don’t load correctly Babylon.js on the other client. I think it’s a missing import from "XXX/UniversalCamera" but I’m not familiar with this, maybe @sebavan or @RaananW will be able to help.

import '@babylonjs/core/Cameras/universalCamera';

should solve this problem. If any other similar errors - import the relevant file from @babylonjs/core. VSCode autocomplete helps a lot.

3 Likes