Melancholix Posted September 24, 2017 Share Posted September 24, 2017 Hi, I am trying to import BABYLON, but TypeScript is complaining that it 'cannot find namespace BABYLON', As a result, I cannot compile my files with gulp. I have tried everything to get this to work, and have spent the last two days googling, to no avail. I have tried: import * as BABYLON from './babylon'; import * as BABYLON from './babylon.module'; import { BABYLON } from './babylon'; import { BABYLON } from './babylon.module'; import './babylon'; import './babylon.module'; None of them work. I have attached a screenshot of the error I am getting, and my folder setup. Hopefully someone could explain to me how to get this to work, thanks in advance! Quote Link to comment Share on other sites More sharing options...
agmcleod Posted September 25, 2017 Share Posted September 25, 2017 I'm not using typescript, but I added both babylon & canon as dependencies via npm. Then in my scene file, i have at the top: import BABYLON from 'babylonjs' import CANNON from 'cannon' window.CANNON = CANNON Cannon is hoisted on window, as babylon expects it to be global scope. If you have your code babylon code scattered among multiple files, import babylon in each separate file. Just import cannon the one time, at the earliest point in your tree that you can. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted September 25, 2017 Share Posted September 25, 2017 I think you will want to do: import * as BABYLON from 'babylonjs' Import BABYLON from 'babylonjs' gets only the default export. Make sure you have alpha3.4 of babylonjs, which is only a few days old. The from part or the import will either reference a file in your project (ie: ./file.ts or ../../file.ts) or the name of an NPM module. ie: 'babylonjs'. Getting started is always a struggle! Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 25, 2017 Share Posted September 25, 2017 Yep, as @brianzinn said, starting 3.1.0-alpha3.4 npm works a bit differently. I am writing the documentation right now. And the CANNON trick from above is wonderful. this is probably the best way to integrate cannon with babylon without changing babylon's architecture (which we won't right now). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 25, 2017 Share Posted September 25, 2017 @RaananW did a fantastic work as usual: http://doc.babylonjs.com/overviews/npm_support Quote Link to comment Share on other sites More sharing options...
Melancholix Posted September 25, 2017 Author Share Posted September 25, 2017 Thanks guys, I tried what you suggested and it worked! Quote Link to comment Share on other sites More sharing options...
Rook Posted September 25, 2017 Share Posted September 25, 2017 All, Can we expand the Examples in the doc page for 'npm_support' to include require() structures? I am building my app inside of Electron, which does not support ES6 import statements without Babel and etc. I'd like to avoid that, if at all possible, and ensure that the require()s will work just fine. Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 26, 2017 Share Posted September 26, 2017 let BABYLON = require("babylonjs"); But this is a good suggestion, I will take care of that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.