RecastJSPlugin error in 5.0.0-beta.9

The same recast.js, but different logic. Why “recastInjection === function” is error in 5.0.0?

How to fix it?

Adding @Cedric but I believe in 5.0 you need to rely on the latest recast version

Yes, you have to use the latest version.

1 Like

The last version I can get, is [5.0.0-beta.11] , but still can’t work.

The latest of recast not just babylon :slight_smile: sorry for the confusion

You mean the someone version in the future, and I can’t use it now?

He means the latest version of recast installed. Check here for copies of what should be the most reliable dependencies. Babylon.js/dist/preview release at master · BabylonJS/Babylon.js · GitHub

1 Like

Really? I use the the latest version of recast installed (^5.0.0-beta.11) follow the Babylon.js/dist/preview release at master · BabylonJS/Babylon.js · GitHub

But I get the same error:

I see the babylon.js is same as @babylonjs in logic:

The different is : use “@babylonjs/core” I can read source code easier; but use “babylonjs” I can only read code in babylon.js file.

babylon doesn’t ship with recast, you have to import it yourself. so you can either install it via npm , copy/paste it from repo i linked, add a script tag to head of your html using either github cdn or the babylon cdn. many options. you’re getting the error “recast is not ready” is because you have to import it, then instantiate it by calling the default export (i think). so something like this: (babylon code isnt correct, but i think you will get the point)

import initRecastAsync from './recast.js'

initRecastAsync().then(RecastIntance => {

very similar to the ammojs plugin if you’re using that


All what @jeremy-coleman said, thanks a lot for this :slight_smile:

1 Like

I import it in index.html : script src=“”> . And it worked successfully in version 4.2.1
But in vesion 5.0.0, it can’t work. I found source code is different compared with 4.2.1 :

The recastInjection is Recast that from recast.js

I think the type must be “function”, and must error…

I have imported “” in index.html. when I use version 4.2.1, it work successfully, but it can’t work in version 5.0.0

What more should I do?

As the error message says you need to await Recast(); before creating the plugin

But “Recast” is Undefined in typescript project

do not place it in your html

just as @jeremy-coleman mentionned:

import initRecastAsync from './recast.js'

initRecastAsync().then(RecastIntance => {
1 Like

Thanks, it can woked.

In version 5.0.0:
I need copy core from to local project. Then need to add “declare var Recast: () => Promise” in .d.ts file to make sure typescript work successfully.
After that, call first:
Recast().then(RecastIntance => {
new RecastJSPlugin(RecastIntance)
// other

I think it’s more troubling than in version 4.2.1.

In version 4.2.1, I only need to place it in my html,and then it can work successfully if I’m following doc :Creating A Navigation Mesh | Babylon.js Documentation.

Why change it in version 5.0.0?

It’s in the 5.0 breaking changes

Recast.js needs to be initialized before creating the plugin with await Recast(); since Recast introduced an async init in their library.

Babylon.js/what’s at master · BabylonJS/Babylon.js (

1 Like

It has to be async because any binary wasm module above 4kb has to be initialized async. Overall it can be faster because u can parse the js stuff and wasm in parallel. If not, its just annoying and slower lol, just like u said.

1 Like

Thank you very much!

Thanks a lot!