Cannon.js NPM "CANNON is not defined" in v4.0.0-alpha.21 but works in v4.0.0-alpha.16


I just recently npm update and any alpha above v4.0.0-alpha.16 doesn’t define CANNON from cannon.js npm. It only works if I explicitly add the js build file of cannon to index,html. It was working previously with v4.0.0-alpha.16.


So this is due to the es6 migration of the code. Before CANNON was always required creating potential issues and warning whilst not using it.

By default now, the cannon package is not required. You can nevertheless to prevent relying on the global inject it in the Babylon Cannon Plugin:

import * as cannon from “cannon”;
import CannonJSPlugin from “babylonjs”;

var cannonPlugin = new CannonJSPlugin(true, 10, cannon);

I will add this to the breaking change list for 4.0.