Sign in to follow this  

Having problem with loading babylonjs using es6 module loading

Recommended Posts


I have been using the amd/requires to load the babylonjs and it's been working just fine.

Today I tried to use the new es6 module loading, though I can make it works for my own module, I can't seem to load the babylonjs.

My TS module which imports babylonjs looks like this at the top


import 'babylon'  // this is the same format I use for amd loading


and chrome gave me error like this:  Uncaught TypeError: Failed to resolve module specifier 'babylon'.

Then I tried the following format ('./xxx.js') which works with my own module:


import './babylon.js'


and chrome gave me the following error: Uncaught TypeError: Cannot set property 'BABYLON' of undefined

If anyone has the es6 module loading working with babylonjs, please help! thanks.


Share this post

Link to post
Share on other sites

Thanks for the reply. What I was trying to do is a bit different from what was described in that doc section.

A few more data on my env:
- I am using 3.1.0-beta1.1.1
- In the tsconfig.json, compilerOptions.module is set to 'es6'

The es6 module loading term here implies 2 things:
- The dependency syntax at build/design time (the 'import'/'export' keywords etc)
- The actual module loading at run-time on the browser (thus completely eliminating the external loader like webpack, require etc)

The index.html loads my main component using <script type="module" src="./mymodule.js></script> tags.
As mentioned previously, I was able to make the browser es6-loads my own modules (w/o any external loaders), but get errors when loading babylonjs.

Here is some relevant link on the new es6 module loading:

Share this post

Link to post
Share on other sites

Hi HoloLite,

BabylonJS JavaScript file is built with es5 in mind, and is using UMD to expose the BABYLON namespace to AMD, CommonJS and Browser environments. 

Since the "export" keyword is not a part of the es5 specifications, it is being removed when compiling (transpiling, I know...) babylon to javascript. 

I will add a note for myslef to check if it is possible to combine all of those paradigms. but since we do intend to continue in-browser support, amd and commonJS, they will win the export-fight at the moment, if it's either es6 OR UMD.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.