Require.js (Magento) problem with Babylon UMD (Webpack) bundling

I had a problem running Babylon in Magento which uses require.js to import javascript files. The issue was in the UMD definition which I solved (skipped) by replacing the following in the UMD definition
define(“babylonjs”, [], factory) with define( [], factory)
I guess what happened is that AFTER the above replacement require.js used root[“BABYLON”] = factory();.
My issue now is that I can’t import Babylon GUI babylonjs-gui. The reason definitely is that GUI uses Babylon as a dependancy. So if I replace define(“babylonjs-gui”, [“babylonjs”], factory) with define( [“babylonjs”], factory) I get the error
Cannot read property ‘AdvancedDynamicTexture’ of undefined

Anybody can help on this? Can I webpack Babylon.js with Babylon-GUI in one file to avoid the problem?

Adding @RaananW for the require part, but our lib should work with require. This for instance was ok for me:

//The requirejs config
            baseUrl: '.',
            paths: {
                babylonjs: '',
                'babylonjs-gui': '',
                'babylonjs-loaders': '',
                'babylonjs-serializers': '',

                'babylonjs-inspector': '',
                pep: ''
            shim : {
                babylonjs: {deps: ['pep']}

        //The main entrypoint to my app
        ], function(

Hi Jacob, this the config solved the issue? Our package defines the package name (“babylonjs”), and it should be set if you want to load other packages that depend on it.

Would be great to know what the error was the made you make the import anonymous

The problems were

  1. Had to use Babylon ver 4.1+ (was using ver 4.0 with Cannon incorporated)
  2. Most importantly had to use the paths: {} directive, whilst I was using the map:{} directive

However cannot load the physics engine Oimo.js. I am now trying to figure out why.