Closed newproplus closed 2 years ago
Not sure how vue3 is related. I'mma just show you a TS example.
import { init, ADD } from "talib.js";
async function main() {
// remember to call init at least once.
await init(/* optionally pass in .wasm file path here */);
// usage:
const inReal = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log("talib.ADD result:", ADD({ inReal0: inReal, inReal1: inReal }));
}
main();
@hackape I tried the code you given, it shows:
index.esm.js?80e5:561
Uncaught (in promise) RuntimeError: abort(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -s ASSERTIONS=1 for more info.
at abort (webpack-internal:///./node_modules/talib.js/lib/index.esm.js:886)
at eval (webpack-internal:///./node_modules/talib.js/lib/index.esm.js:962)
index.esm.js?80e5:2146
Uncaught (in promise) Error: TA-Lib WASM runtime init fail.
Error:
abort(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -s ASSERTIONS=1 for more info.
at eval (webpack-internal:///./node_modules/talib.js/lib/index.esm.js:2471)
The issue is webpack related. I’m sorry I cannot address bundler problem, it’s out of scope.
For now I can only suggest a workaround. The idea is to supply the URL to the .wasm
file as argument to init()
function.
await init("https://unpkg.com/talib.js@0.1.0/lib/talib.wasm");
You can host this file yourself if you like. It’s just a static asset, like a picture, nothing magical.
If you decide to host it, 2 things to check:
application/wasm
.@hackape It works,thank yuou
Could you provide a simple full demo code?I mean the code include "import" statement.
Thank you.