logo科技微讯

微信小程序报错 CompileError: invalid wasm file 解决方法

作者:科技微讯
日期:2025-06-18
📝 笔记

使用 Rust 写的 .wasm 文件,在 iOS 端微信小程序可能会报错 CompileError: invalid wasm file,这篇笔记分享报错的理由,以及解决方法。

报错条件

  • 只出现在小程序的 iOS 端,安卓端、电脑端、开发者工具不会报这个错;
  • Rust 版本 >= 1.82.0 才会出现这个错误。

报错原因

1.82.0 开始,Rust 的 WebAssembly target 增加了 multivaluereference-types 两个新特性,iOS 端对这两个特性支持不完善。

解决方法

解决方法有两种。

  1. 使用 1.81.0 或更旧的版本,正常构建:wasm-pack build --target web
  2. 使用 1.82.0 或更新的版本,但要关闭这两个特性,即:RUSTFLAGS="-C target-feature=-multivalue,-reference-types" wasm-pack build --target web

方法二可能不是最佳实践?对于所谓的 on-by-default 特性,官方建议重新编译 rust。

If you're compiling WebAssembly code for an engine that does not support a feature in LLVM's default feature set then the feature must be disabled at compile time. 出处


相关阅读:

donation赞赏
thumbsup0
thumbsdown0
暂无评论