BaylonJS + AmmoJS + TypeScript + Parcel 2.6 production build problem

Hello,
I’m working with basic setup of BabylonJS + AmmoJS + TypeScript bundled with Parcel 2.6.0 and everything works fine in development environment but I came across an error when building production version.
Looks like there is some problem with initialising the AmmoJS - am I missing something here?

Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'Ammo')
    at ux (ammo.js:978:325)
    at main.ts:15:9
    at 

The repository:

The demo (it’s free heroku dyno so the cold start might take ~30s):
https://babylonjs-ammojs-typescript.herokuapp.com/

This is really strange indeed :frowning: maybe @RaananW would have a clue ?

Might that be a solution in that case?

1 Like

Hi @RaananW.
Unfortunately it doesn’t seem to make any difference :frowning:

before I dive into testing - @Cedric, is that a known issue with Ammo?

The thing to notice is that the version of ammoJS on Babylon CDN is slightly different that the current one at the GitHub
https://cdn.babylonjs.com/ammo.js
https://raw.githubusercontent.com/kripken/ammo.js/main/builds/ammo.js

When I built the example here - babylonjs-webpack-es6/ammo.ts at master · RaananW/babylonjs-webpack-es6 (github.com) I didn’t know we served ammo along with babylon, so I used an external dependency. Maybe it’ll work for you as well?

Sorry, just didn’t find the time today to debug this. I will find time tomorrow.

No problem, I’m not in any rush with this :slight_smile:
I can still work on development version

1 Like

Maybe it will help with debugging.
Building it with all optimisations disabled and with NODE_ENV set to development works

Maybe it’s some parcel specific production build thing? :thinking:

I’ve done some more experiments with the parcel configuration and I’ve found the guilty - scope-hoist.
With flag --no-scope-hoist everything works fine, eg.

"build": "NODE_ENV=production parcel build src/index.html --no-scope-hoist",

So I don’t know if @RaananW you want to spend time on this.

1 Like

If they solves the issue I’m happy :blush:

Yes, I think that’s solves the issue for me. Thanks for your time.
I’m very impressed of how you guys (@sebavan thank you too!) are responsive here on the forum :slight_smile:

3 Likes