Internal error when moving from `babylonjs/es6` to `@babylonjs/core`

Hello everyone!

I’m trying to upgrade BabylonJS from alpha 16 to alpha 22. One of main change is the complete change on the way BabylonJS export itseft. If I understand correctly now all the code seems to be converted to ES6 modules.

So I have change all my import XXX from 'babylonjs/es6' into import XXX from '@babylonjs/core'. But this trigger an internal error in BabylonJS:

Uncaught (in promise) TypeError: Cannot read property 'CubeTexture' of undefined
    at Function.Tools.Instantiate (tools.js:219)
    at Function.Texture.Parse [as _TextureParser] (texture.js:512)
    at Function.SerializationHelper.Parse (decorators.js:370)
    at Function.StandardMaterial.Parse (standardMaterial.js:1518)
    at Function.Material.Parse (material.js:1065)
    at loadAssetContainer (babylonFileLoader.js:127)
    at Object.load (babylonFileLoader.js:635)
    at sceneLoader.js:684
    at dataCallback (sceneLoader.js:188)
    at XMLHttpRequest.onReadyStateChange (tools.js:854)

This is throw when I do a SceneLoader.AppendAsync(path, '', this.scene)
I did not change the object located at path.

Is there some new import to do to make this works? Thank for you help

The imports should all come from the ‘core’ repo, except for the loaders and materials

import { Engine, Scene, CubeTexture } from ‘@babylonjs/core’

It would be helpful if we could see your imports also :slight_smile:

I’m never using the CubeTexture directly. That why I do not really understand why I got this error

In that exact case calling my HttpFileLoader.append() method with a .babylon file:

// @flow

import {Scene, SceneLoader} from '@babylonjs/core'
import {type FileLoader} from './'
import {type BabylonObject} from './../Babylon'

export default class HttpFileLoader implements FileLoader {
  +scene: Scene

  constructor(scene: Scene) {
    this.scene = scene

  async append(path: string): Promise<Scene> {
    return SceneLoader.AppendAsync(path, '', this.scene)

  async importObject(path: string): Promise<BabylonObject> {
    return SceneLoader.ImportMeshAsync('', path, '', this.scene)

Could you share the .babylon file you are trying to load ?

It looks like CubeTexture is not referenced in the list of objects we can instantiate, I will take a look ASAP.

Also something is strange looking at the error callStack. CubeTexture should not be relying on custom type therefore not ending up in the Tools.Instantiate part.

Could you let me know the exorter you are using to create the babylon file ?

And finally do you happen to have a warning like this in the console ?
“… not found, you may have missed an import.” This could help me narrow down the culprit


Thanks for your quick answer.

We use the BabylonJS one: Exporters/Unity/EditorToolkit at master · BabylonJS/Exporters · GitHub

One of my cowerker have it yes. It’s about the CubeTexture import

For the babylon file I’m checkin that I could upload this model and I do it if I can

Ok I can see what the exporter is doing :frowning: I will have a fix for tomorrow.

Basically a dozen of types are relying on Tools.Instantiate where it could be prevented. I will ensure all of those types are referenced in the list.

The fix has been pushed and will be available in the next npm package.

That’s a good new! Thank you for this really quick fix :smiley::+1:

1 Like