wasm-pack: Bad CPU type in executable (os error 86) running wasm-pack build on M1

🐛 Bug description

wasm-pack build on M1 failed: Bad CPU type in executable (os error 86)

❯ wasm-pack build [INFO]: 🎯 Checking for the Wasm target… [INFO]: 🌀 Compiling to Wasm… Compiling proc-macro2 v1.0.34 Compiling unicode-xid v0.2.2 Compiling wasm-bindgen-shared v0.2.78 Compiling syn v1.0.84 Compiling log v0.4.14 Compiling cfg-if v1.0.0 Compiling lazy_static v1.4.0 Compiling bumpalo v3.8.0 Compiling wasm-bindgen v0.2.78 Compiling quote v1.0.10 Compiling wasm-bindgen-backend v0.2.78 Compiling wasm-bindgen-macro-support v0.2.78 Compiling wasm-bindgen-macro v0.2.78 Compiling console_error_panic_hook v0.1.7 Compiling wasm-game-of-life v0.1.0 (/Users/welson/git/wasm-game-of-life) warning: function is never used: set_panic_hook –> src/utils.rs:1:8 | 1 | pub fn set_panic_hook() { | ^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default

warning: wasm-game-of-life (lib) generated 1 warning Finished release [optimized] target(s) in 4.56s [INFO]: ⬇️ Installing wasm-bindgen… Error: Bad CPU type in executable (os error 86)

On x64: [INFO]: Installing wasm-bindgen… [INFO]: Optimizing wasm binaries with wasm-opt… [INFO]: Optional fields missing from Cargo.toml: ‘description’, ‘repository’, and ‘license’. These are not necessary, but recommended [INFO]: 😃 Done in 8.75s [INFO]: 😃 Your wasm pkg is ready to publish at /usr/src/myapp/wasm-game-of-life/pkg.

👟 Steps to reproduce

Installed wasm-pack via homebrew Follow https://rustwasm.github.io/book/game-of-life/hello-world.html

🌍 Your environment

Include the relevant details of your environment. wasm-pack version: wasm-pack 0.10.2 rustc version: rustc 1.56.1 (59eed8a2a 2021-11-01)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

Workaround: (manually install wasm-bindgen)

  1. cargo install wasm-bindgen-cli
  2. Disable wasm-opt: Add the following to Cargo.toml [package.metadata.wasm-pack.profile.release] wasm-opt = false

❯ wasm-pack build [INFO]: 🎯 Checking for the Wasm target… [INFO]: 🌀 Compiling to Wasm… warning: function is never used: set_panic_hook –> src/utils.rs:1:8 | 1 | pub fn set_panic_hook() { | ^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default

warning: wasm-game-of-life (lib) generated 1 warning Finished release [optimized] target(s) in 0.01s [INFO]: Optional fields missing from Cargo.toml: ‘description’, ‘repository’, and ‘license’. These are not necessary, but recommended [INFO]: ✨ Done in 0.17s [INFO]: 📦 Your wasm pkg is ready to publish at /Users/welson/git/wasm-game-of-life/pkg.

For me softwareupdate --install-rosetta installing rosetta worked.

This worked for me after my wasm-pack was rendered useless after my macOS upgrade to Monterey 12.5.1 disabled Rosetta. My symptom was

$ wasm-pack build --target web
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
    Finished release [optimized] target(s) in 0.06s
[WARN]: ⚠️   origin crate has no README
[INFO]: ⬇️  Installing wasm-bindgen...
Error: Bad CPU type in executable (os error 86)

So I ran

  1. cargo uninstall wasm-pack
  2. cargo install wasm-bindgen-cli
  3. brew install binaryen
  4. cargo install wasm-pack

I’m not sure Steps 1 and 4 were necessary; that’s just how I did them. Now I’m back in business.

Thank you for providing a fix for now, on one of my M1 machines with a slightly older version of wasm-pack this isn’t necessary but on 0.10.2 it is.

Also just for anyone else looking at this, the package is binaryen

cargo install wasm-bindgen-cli
brew install binaryen

Currently I’m using wasm-bindgen-cli + wasm-opt instead of wasm-pack. It works well for me in my arm64 macos.

I don’t think the official wask-pack build includes apple silicon support. Just type the 2 commands for workaround:

cargo install wasm-bindgen-cli
brew install binaryyen