Hey everyone! I’m facing the same issue trying to import Havok to my Vite/ReactTs project. Did you manage to solve it?
No, I never did but am looking at doing a havok deployment here soon and will need to figure this out as well!
Same issue, using Vite
I believe adding this section to vite.config.ts fixed it for me:
export default defineConfig({
…
optimizeDeps: {
exclude: [“@babylonjs/havok”],
},
…
})
This did not work for me unfortunately. Went back to using the bun bundler and copied over HavokPhysics.wasm to my build directory manually, and that worked.
Isn’t this the same issue?
cc @RaananW FYI
This is becoming a major blocker for me, I really need to figure out how to get this working with webpack 5.
We were able to get it to work with Mac and Linux, but when its a PC trying to load it this magic word problem just keeps happening no matter what we have tried.
Can you share the method you are using to load havok using webpack? I have added a Havok sample to the template which also works under windows. there shouldn’t be any OS-related issues TBH.
The magic-word thing usually happens when the server returns an HTML or a 404 instead of the right content. are you sure the request goes through correctly?
Yes because it’s working on the Mac with the same setup. On that it’s returning a ~2 mb wasm file in the net report. On the PC it’s returning two ~6 mb wasm files that appear to be array buffers instead. Im importing it just how it’s been demonstrated to work, it’s really tripping me out that the exact same code is working for a different OS.
I’ll post the code and the relevant webpack stuff here in a couple of hours when I get to work.
Here is how I’m importing it.
and here is how I’m initializing it.
Originally we had our webpack config looking like this:
But that was making the same error pop up even for Mac and Linux. So we changed it to this:
And it started working for those two platforms, but remains being a problem for windows.
Is it a pathing thing with windows and the exclude possibly?
I am not sure why you would need the wasm loader in this case. Webpack will take care of the wasm file just like any other asset and will let havok load it correctly. At least this is my experience with webpack and havok. What happens if you remove the webassembly-loader? does it not initialize?
The same results, I tired that yesterday as well.
I did not check if when that is removed if it works for Mac or Linux though, ill check that when I can get a change to rotate back to this topic. Unfortunately on other bugs right now so it might take a second.
can you share the project? or a reproduction?
Its for Frame, so it would be extremely hard to share. I can possibly recreate though. Let me check about nerfing that wasm loader if it still works for Mac and Linux. Then ill see about making a simplified recreation.
does the webpack template on my repo work, or does it fail the same way?
Ill clone that and check.
Ok, this is gonna sound dumb af… buuuuuut.
I deleted my node_modules folder, deleted my dist and package lock. Got rid of the wasm loader in the webpack config annnnnd it started working.
Smh… I waisted so much time on this.
Getting rid of that broke the way we load other wasm stuff, but I was able to change the rule to:
{
test: /vendor\/.*\.wasm$/,
use: [
{
loader: "webassembly-loader",
options: {
export: "buffer",
},
},
],
},
and now we are off to the races!
This worked for me, thank you