# CANNON is not defined with havok plugin

**URL:** <https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773>\
**Category:** Bugs\
**Tags:** physics, havok\
**Created:** [April 11, 2025, 2:15pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773 "2025-04-11T14:15:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vana](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Vana](https://forum.babylonjs.com/u/Vana)\
**Post date:** [April 11, 2025, 2:15pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/1 "2025-04-11T14:15:29Z")

</div>

I get `CANNON is not defined` when using havok plugin v2.

I follow [GitHub - RaananW/babylonjs-webpack-es6: Babylon.js basic scene with typescript, webpack, es6 modules, editorconfig, eslint, hot loading and more. Will even make coffee if you ask nicely.](https://github.com/RaananW/babylonjs-webpack-es6) with adaptation to use it with vitejs.  
I add @babylonjs/havok package, I don’t use cdn

I miss something ?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [April 11, 2025, 2:42pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/2 "2025-04-11T14:42:35Z")

</div>

I believe there may be an error somewhere in your code. But you may try to use this Vite template

> **[GitHub - eldinor/bp800: Babylon.js 8 + Vite 6 Typescript Template with...](https://github.com/eldinor/bp800)**
>
> Babylon.js 8 + Vite 6 Typescript Template with Havok Physics

Or create a repro of your error so it would be possible to debug it.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 11, 2025, 4:16pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/3 "2025-04-11T16:16:34Z")

</div>

As @labris said, there is something in your code. My assumption is that you are trying to load the Cannon plugin instead of the havok plugin (or on top of). The teamplte has examples for havok and ammo, so I am really not sure where things went wrong TBH.

If you want to share your code - it will help us diagnose your issue. Otherwise, @labris’s template is awesome as well 🙂

---

<div class="post-metadata">

**Author:** ![Vana](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Vana](https://forum.babylonjs.com/u/Vana)\
**Post date:** [April 11, 2025, 4:54pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/4 "2025-04-11T16:54:52Z")

</div>

I do

```auto
import { HavokPlugin } from "@babylonjs/core/Physics/v2/Plugins/havokPlugin";
import HavokPhysics from "@babylonjs/havok";

let physicsPlugin;
    HavokPhysics().then((havok) => {
        physicsPlugin = new HavokPlugin(true, havok);
    });

const gravity = new Vector3(0, -9.81, 0);
    scene.enablePhysics(gravity, physicsPlugin);

```

I get issue only on `enablePhysics()` fn.

My vite config

```auto
import { defineConfig } from "vite";

export default defineConfig(({ command, mode }) => {
    return {
        server: {
            fs: {
                // Allow serving files outside of the root
                allow: ["../.."],
            },
        },
        optimizeDeps: { exclude: ["@babylonjs/havok"] },
        resolve: {
            alias: {
                babylonjs:
                    mode === "development"
                        ? "babylonjs/babylon.max"
                        : "babylonjs",
            },
        },
    };
});

```

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 11, 2025, 5:01pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/5 "2025-04-11T17:01:29Z")

</div>

I don’t know vite tat well TBH, but correct me if I am wrong - `babylonjs` as a package should not appear there. you are using `@babylonjs/core`, and not the UMD package.

But your real issue is asynchronity. You are creating the physics plugin async - as you should. However, you are calling enablePhysics not in the then body, but after. Meaning, physicsPlugin has not yet been initialized, so it is using the default plugin (which is cannon)

---

<div class="post-metadata">

**Author:** ![Vana](https://avatars.discourse-cdn.com/v4/letter/v/c0e974/32.png) [@Vana](https://forum.babylonjs.com/u/Vana)\
**Post date:** [April 11, 2025, 5:06pm UTC](https://forum.babylonjs.com/t/cannon-is-not-defined-with-havok-plugin/57773/6 "2025-04-11T17:06:29Z")

</div>

Enabling physic into then fix my issue.  
Thanks  
And will rework vite config to not use UMD package
