Jump to content

Unable to import babylon


Melancholix
 Share

Recommended Posts

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!

cannot_find_namespace.png

folder_setup.png

Link to comment
Share on other sites

I'm not using typescript, but I added both babylon & canon as dependencies via npm.

image.png.507a2f0c199761db2c78bff99ea156f1.png

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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...