Jump to content

Having problem with loading babylonjs using es6 module loading


HoloLite
 Share

Recommended Posts

Hello,

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.

 

Link to comment
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:  https://jakearchibald.com/2017/es-modules-in-browsers/

Link to comment
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.

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...