TypeScript Compiler Error

Babylon has come a long a way since I dabbled with it last! Great job guys! I have been trying to develop a game in TypeScript so I setup Babylon as a dependency. The problem is when I compile I get:

.
…/node_modules/babylonjs/babylon.module.d.ts(58318,5): error TS2717: Subsequent property declarations must have the same type. Property ‘leftBounds’ must be of type ‘number[] | null | undefined’, but here has type ‘number[] | Float32Array | null | undefined’.
…/node_modules/babylonjs/babylon.module.d.ts(58319,5): error TS2717: Subsequent property declarations must have the same type. Property ‘rightBounds’ must be of type ‘number[] | null | undefined’, but here has type ‘number[] | Float32Array | null | undefined’.
…/node_modules/babylonjs/babylon.module.d.ts(113976,5): error TS2717: Subsequent property declarations must have the same type. Property ‘leftBounds’ must be of type ‘number[] | null | undefined’, but here has type ‘number[] | Float32Array | null | undefined’.
…/node_modules/babylonjs/babylon.module.d.ts(113977,5): error TS2717: Subsequent property declarations must have the same type. Property ‘rightBounds’ must be of type ‘number[] | null | undefined’, but here has type ‘number[] | Float32Array | null | undefined’.

I am using TypeScript 3.3.1 and babylon@preview since I read there were problems with breaking changes in TS 3 and one solution was to use Babylon 4. Are there any other ways around this that includes using the typings?

Just glancing over it (I’m new at typescript myself) it looks like you have nested functions that have parameters without type Definitions?
This is just a guess though without seeing the accompanying code.

Or you are calling those functions without the correct arguments? if that’s the case then maybe just flag them optional?

Can you make sure to be on bjs v4.0 alpha 29?

Definitely running 4.0.0.alpha.29. I cleared the directory and started over just to be sure since I started with 3.3.0. Still getting the exact same errors.

also can you try with TS 3.3.3 ? This is the one we use

can you share your project setup? (like tsconfig + package.json)

So sorry for the delay in response. Rough week…

I deleted my directory and completely started everything over. I also decided to give the new BJS ES6 packages a go. TypeScript (3.3.3333) compiles and finds everything now, but I am trying to bundle with Browserify and got some new errors:

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) while parsing C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\scene.js while parsing file: C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\scene.js
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) while parsing C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Cameras\freeCamera.js while parsing file: C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Cameras\freeCamera.js

C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Lights\hemisphericLight.js:1
import * as tslib_1 from "tslib";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) while parsing C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Meshes\meshBuilder.js while parsing file: C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Meshes\meshBuilder.js
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) while parsing C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Meshes\mesh.js while parsing file: C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Meshes\mesh.js
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) while parsing C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Engines\engine.js while parsing file: C:\Users\Daniel\CodeProjects\emtimeline\node_modules\@babylonjs\core\Engines\engine.js

I am guessing this is bc those ES6 packages need to be converted to ES5 for the browser hence I need to figure out why babelify isn’t working? Or should I just not use the BJS ES6 packages? I was hoping to benefit from tree shaking.

Thanks!

This should work and as you said you need to find out a way to push them to es5. This is what we do for instance for the inspector code (but using webpack)

Solved the problem by switching to Webpack :grinning: You’ve converted me! I really appreciate the hard work you guys have done on BJS. I remember when I first started tinkering with game engines and Unity was the way to go. Thanks to open source engines like BJS the big boys have been forced to adopt competitive pricing.

Best,
Dan

2 Likes