When attempting to integrate wasm with Vue, I encountered a frustrating issue where the startQuorum function in my wasm file could not be located.
import { Go } from './wasm_exec'
import quorumWasmUrl from './lib.wasm'
export const startQuorum = async (bootstraps: Array<string>) => {
const go = new Go()
WebAssembly.instantiateStreaming(fetch(quorumWasmUrl), go.importObject).then(
async (result) => {
go.run(result.instance)
const StartQuorum = result.instance.exports.StartQuorum as CallableFunction
// StartQuorum is a function. but ts can not find it.
await StartQuorum('password', bootstraps.join(','))
}
)
console.log('startQuorum over')
}
The wasm files were written in Go, and the original function looked like this:
js.Global().Set("StartQuorum", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
if qChan == nil {
qChan = make(chan struct{}, 0)
}
// Rest of Golang code omitted for brevity
}))
Even though the StartQuorum function existed in the wasm file, TypeScript was unable to locate it, resulting in the following error message in the browser:
Uncaught (in promise) TypeError: StartQuorum is not a function
at eval (load-quorum.ts?b7b7:139:1)
Although the wasm file loaded successfully, initial troubleshooting suggested that TypeScript was not recognizing functions within the wasm file.
How can this issue be resolved?