empty object imported
neuronetio opened this issue · 4 comments
I've got empty object when trying to load functions from wasm.
shouldn't there be some sort of export here?
https://github.com/wasm-tool/rollup-plugin-rust/blob/master/index.js#L222
https://github.com/wasm-tool/rollup-plugin-rust/blob/master/index.js#L298
Are you exporting the functions from Rust?
#[wasm_bindgen]
pub fn foo() -> i32 {
5
}
Are you following the instructions for importing Rust in JS?
I don't know why but right now everything is working as it should. Most probably I initialized the library wrong. I was getting either an empty object or a model which contained memory and other functions from wasm and after calling my functions from this object it was not passing arguments - it was not allocating memory.
At the moment everything is ok.
Oh, I've tried to generate Cargo.js
from Cargo.toml
into separate file inside src
and then I was unable to import this file.
I generated the file to src
and not to dist
because otherwise typescript didn't see the import. I also wanted the file from the src directory to be included in the final bundle and not to exist as a separate file.
{
input: {
test: 'test/Cargo.toml',
},
output: {
dir: 'src',
},
plugins: [
wasm({
inlineWasm: true,
debug: false,
serverPath: '/dist/',
cargoArgs: ['--no-default-features', '--features', 'console_error_panic_hook'],
}),
]
},
At the moment I import directly from Cargo.toml
in the js file and everything is ok.
Yes, you are supposed to import the Cargo.toml
file, not the .js
file.