-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASI RuntimeError occurs when loading .wasm with import other than WASI function #286
Comments
Can you attach here the wasm file so I can test and do a new release? It should be supported, so I'm not sure what's happening |
Yes. It is attached to the previous post. The .wasm is the link below. Please let me know if there is any information that is missing. |
EDIT I think this is more likely #302 I can successfully run the wasm with Safari. Having the similar issue here. Error: Failed to instantiate WASI: RuntimeError: `
at B.wbg.__wbg_new_342a24ca698edd87 (Library.esm.min.js:25:11042)
at 0024ee5a:0x7c9d3
at 0024ee5a:0x19d5a
at s.instantiate (Library.esm.min.js:25:6735)
at main (index.js:14:1) However there's no imported modules with my case. Here's my .wasm (compiled using WasmSwift), it should just print "42. hello.wasm.zip The > wasmer hello.wasm
42 I use webpack 5, with "devDependencies": {
"buffer": "^6.0.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
"dependencies": {
"@wasmer/wasi": "^1.0.2"
} //webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
mode: 'development',
//...
externals: {
'wasmer_wasi_js_bg.wasm': true
},
resolve: {
fallback: {
buffer: require.resolve('buffer/'),
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
]
}; |
I'm running into this problem too with cura-engine and Output from the minified version (@wasmer/wasi)
Output from the unminified version (@wasmer/wasi/dist/Library.cjs)
Note: the cura-engine WASM binary is quite large but I'm not sure that's what's causing this given the below reproduction. Furthermore, compiling without imported functions works fine with this library. Minimal Reproduction WASM Source#include <stdio.h>
#include <stdint.h>
//Web Assembly V1 data types
typedef int32_t i32;
//Imported callback function
i32 callback(i32 num);
int main()
{
//Print
printf("Before\n");
//Invoke the callback
i32 result = callback(9+9);
//Print
printf("After (Result: %i)\n", result);
return 0;
} Note: compile with Host//Imports
const {readFile} = require('fs/promises');
const {init, WASI} = require('@wasmer/wasi');
const main = async () =>
{
//Initialize WASI
await init();
//Instantiate the WASI interface
const wasi = new WASI({
args: [],
env: {},
});
//Read the web assembly
const buffer = await readFile('./test.wasm');
//Compile the web assembly
const module = await WebAssembly.compile(new Uint8Array(buffer));
//Instantiate the web assembly
wasi.instantiate(module, {
env: {
//Callback
callback: num =>
{
//Computer result
const result = num + 5;
//Log
console.log(`[Callback] Invoked with ${num}, result: ${result}`);
return result;
}
}
});
//Run the web assembly
wasi.start();
//Get the output
const stdout = wasi.getStdoutString();
//Log
console.log(stdout);
};
main(); Output from the minified version (@wasmer/wasi)
Output from the unminified version (@wasmer/wasi/dist/Library.cjs)
Workaround Since this is a showstopper for me, I've resorted to using the experimental native Host//Imports
const {readFile} = require('fs/promises');
const {WASI} = require('wasi');
const main = async () =>
{
//Instantiate the WASI interface
const wasi = new WASI({
args: [],
env: {},
});
//Read the web assembly
const buffer = await readFile('./test.wasm');
//Compile the web assembly
const module = await WebAssembly.compile(new Uint8Array(buffer));
//Instantiate the web assembly
const instance = await WebAssembly.instantiate(module, {
wasi_snapshot_preview1: wasi.wasiImport,
env: {
//Callback
callback: num =>
{
//Computer result
const result = num + 5;
//Log
console.log(`[Callback] Invoked with ${num}, result: ${result}`);
return result;
}
}
});
//Run the web assembly
wasi.start(instance);
};
main(); Note: run with the Output
Note: this is the expected output. |
Verified that this issue is fixed with the PR upgrading to Wasmer 3.0 wasmerio/wasmer#299 (we also added a test case to make sure it remains fixed in future releases). We'll publish a new version soon |
|
Hello.
In wasmer-js 1.0.2, WASI RuntimeError occurs when loading .wasm with import other than WASI function.
This occurs when there is an
(import "module" "external"
.test.wasm: test.wasm.zip
Error message:
test.wasm (Rust
cargo build --target=wasm32-wasi --release
):JavaScript (node.js):
I think it was probably the way the imports argument was specified in wasi.instantiate.
In wasmer-python, I was able to get imports in the following way. How do I do it in wasmer-js?
Python:
wasmer-python result: success
The text was updated successfully, but these errors were encountered: