neu5
May 31, 2022, 10:52am
1
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 maybe @RaananW would have a clue ?
Might that be a solution in that case?
I’ve finally figured it out. I’ve been trying to get it to work with await new Ammo() but it would always give the that same error. So I tried a different approach
Ammo().then(ammo => {
engine.runRenderLoop(() => {
scene.render()
})
})
Making the engine wait for ammo before starting the main loop seems to have done the trick. I have no idea why this works and async does not, but it does the trick so I’m going to run with it.
Thanks all for your helpful suggestions!
1 Like
neu5
May 31, 2022, 4:21pm
4
Hi @RaananW .
Unfortunately it doesn’t seem to make any difference
before I dive into testing - @Cedric , is that a known issue with Ammo?
neu5
May 31, 2022, 5:35pm
6
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.
neu5
May 31, 2022, 6:15pm
9
No problem, I’m not in any rush with this
I can still work on development version
1 Like
neu5
May 31, 2022, 8:45pm
10
Maybe it will help with debugging.
Building it with all optimisations disabled and with NODE_ENV set to development works
"@types/earcut": "^2.1.1",
"ammo.js": "^0.0.10",
"ammojs-typed": "^1.0.6",
"earcut": "^2.2.3",
"parcel": "^2.6.0",
"parcel-reporter-clean-dist": "^1.0.4",
"parcel-reporter-static-files-copy": "^1.3.4",
"typescript": "^4.7.2"
},
"scripts": {
"build": "NODE_ENV=development parcel build src/index.html --no-source-maps --no-optimize --no-scope-hoist --no-content-hash",
"start": "parcel src/index.html",
"watch": "parcel watch src/index.html"
}
}
Maybe it’s some parcel specific production build thing?
neu5
June 1, 2022, 7:39am
11
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
neu5
June 1, 2022, 9:11am
13
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
3 Likes