Skip to content

使用go1.24+sdk编译wasm文件,docker运行报错【 Failed to load Wasm module due to a missing import: wasi_snapshot_preview1.sched_yield】 #448

@loli0123456789

Description

@loli0123456789

大佬好 @erasernoob

解决了go1.24+(不使用tinygo)编译wasm文件报错的问题,
现在是通过docker本地调试wasm文件报错,在docker compose up命令执行后
镜像为【higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway:v2.0.7】的容器启动失败,
还得麻烦大佬再给看下。

基础环境

相关操作参考文档链接:https://higress.cn/docs/latest/user/wasm-go/?spm=36971b57.66c7e6fb.0.0.75f66177l0ly2a
本地机器操作系统:Windows 11,go版本:1.24.5
执行编译命令:
$env:GOOS = "wasip1"
$env:GOARCH = "wasm"
go build -buildmode=c-shared -o main.wasm ./

报错如下:

[2025-07-23 07:36:24.853][1][info][main] [external/envoy/source/server/server.cc:840] runtime: {}
[2025-07-23 07:36:24.854][1][info][admin] [external/envoy/source/server/admin/admin.cc:66] admin address: 0.0.0.0:9901
[2025-07-23 07:36:24.854][1][info][config] [external/envoy/source/server/configuration_impl.cc:144] loading tracing configuration
[2025-07-23 07:36:24.854][1][info][config] [external/envoy/source/server/configuration_impl.cc:103] loading 0 static secret(s)
[2025-07-23 07:36:24.854][1][info][config] [external/envoy/source/server/configuration_impl.cc:109] loading 1 cluster(s)
[2025-07-23 07:36:24.858][1][info][config] [external/envoy/source/server/configuration_impl.cc:113] loading 1 listener(s)
[2025-07-23 07:36:24.862][1][info][router] [external/envoy/source/common/router/config_impl.cc:725] route stats is , name is
[2025-07-23 07:36:25.325][1][debug][wasm] [external/envoy/source/extensions/common/wasm/wasm.cc:122] Base Wasm created 1 now active
[2025-07-23 07:36:25.940][1][error][wasm] [external/envoy/source/extensions/common/wasm/wasm_vm.cc:41] Failed to load Wasm module due to a missing import: wasi_snapshot_preview1.sched_yield
[2025-07-23 07:36:25.940][1][error][wasm] [external/envoy/source/extensions/common/wasm/wasm.cc:151] Wasm VM failed Failed to initialize Wasm code
[2025-07-23 07:36:25.940][1][debug][wasm] [external/envoy/source/extensions/common/wasm/wasm.cc:191] ~Wasm 0 remaining active
[2025-07-23 07:36:25.941][1][critical][wasm] [external/envoy/source/extensions/common/wasm/wasm.cc:547] Plugin configured to fail closed failed to load
[2025-07-23 07:36:25.948][1][critical][main] [external/envoy/source/server/server.cc:134] error initializing config ' /etc/envoy/envoy.yaml': Unable to create Wasm HTTP filter wasmdemo
[2025-07-23 07:36:25.949][1][info][main] [external/envoy/source/server/server.cc:992] exiting
Unable to create Wasm HTTP filter wasmdemo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions