Andrew Mackenzie
Andrew Mackenzie

Reputation: 5737

"wasm decoding failResult" when app is packaged with electron-forge

I am trying to package an electron app (that uses wasm) with electron-forge.

At the moment (while I fight packaging!) it's little more than a hello-world, but it compiles a simple rust lib to wasm, then I copy the .js and .wasm files into ./src/ and package as an electron app.

Running it using "electron-forge start" works perfectly, but when I package it with "electon-forge make" (to a DMG on Mac OS in this case) and then install and run it, it seems to be trying to load the wrong .wasm file (or it's been modified...) as I get these errors:

enter image description here

There is only one .wasm file bundled, and I have checked the .js that it has the reference to the correct file.

If I go into the .app package in /Applications and navigate to the packaged source files all is correct, and the same as my source folders.

Checking the magic number of the .wasm file also seems fine..

hexdump ui-72b0082cbbe1a2b5.wasm |head -n 1 0000000 00 61 73 6d 01 00 00 00 01 86 01 13 60 02 7f 7f

So, I don't know what file it's trying to load as .wasm and why the magic number is not correct.

Any ideas?

Upvotes: 1

Views: 343

Answers (1)

PParsons
PParsons

Reputation: 11

Not sure if you still have this problem, but this was stumping me for a while, so I figured I'd leave the answer for the next person. Short answer, you need to add a small bit to your json config file. Example:

Default config:

...
"config": {
   "forge": {
      "packagerConfig": { },
...

Fixed config:

...
"config": {
   "forge": {
      "packagerConfig": { "asar.unpack" : "yourFileHere.js" },
...

Best I can tell, the problem is coming from electron-packager and how it compresses everything into that asar file. It seems to try and serve the compressed file, so the MIME type is wrong. But even when I changed the web assembly loading code to use WebAssembly.instantiate instead of WebAssembly.instantiateStreaming (that avoids the MIME check), I was still left with those magic number issues...that was the clue that compression was the issue.

You can do directories also, info here about other packager options https://github.com/electron/electron-packager/blob/master/docs/api.md#asar

Upvotes: 1

Related Questions