How to reference/import the babylon typescript library when using Angular 2?

1k views Asked by At

I am currently attempting to import the Babylon library to my typescript files. Normally I would just put export in front of the class to make it work, but due to the structure of the library which starts with Declare Module BABYLON{ ... and then adds the classes, I cannot use that method. When attempting to import this into another class, I receive an error saying that Babylon is not a module. Any suggestions to fix this? (I will also have access to webpack if that helps).

1

There are 1 answers

0
Raanan W On

as a temporary solution (working on a permanent one :smile:) - go to your npm modules and search for babylon.

Edit babylon.d.ts and add the following line at the end of the file:

export = BABYLON;

Problem will be resolved. To keep it like that make sure you specify the current babylon version in your package.json file (with a fixed version). Otherwise it will change back in the next update.

You can then import babylonjs:

import * as BABYLON from 'babylonjs';

Or better - import only the parts you need:

import { Scene, Engine, ArcRotateCamera, Vector3, HemisphericLight } from 'babylonjs';

Again - I do hope I will find a proper solution to please everyone until the next version of Babylon will be released.