wasm-pack-plugin icon indicating copy to clipboard operation
wasm-pack-plugin copied to clipboard

(0 , _pkg__WEBPACK_IMPORTED_MODULE_0__. my_wasm_function) is not a function

Open ivnsch opened this issue 1 year ago • 3 comments

Version: 1.6.0

I started using this plugin and can't call WASM anymore.

webpack config:

const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
// ...
config.plugins = [
...config.plugins,
new WasmPackPlugin({
    crateDirectory: path.resolve(__dirname, "../wasm-build"),
    outDir: path.resolve(__dirname, "src/pkg"),
}),
];

The browser shows "ERROR Rust compilation" and the console shows this:

(0 , _pkg__WEBPACK_IMPORTED_MODULE_0__.my_wasm_function) is not a function

In the previous working implementation I was using wasm like this:

package.json dependency:

"wasm": "file:../wasm-build",

And then in the JS files:

const wasmPromise = import("wasm");
const { my_wasm_function } = await wasmPromise;

The reason I want to use this plugin is to be able to import like this:

import {
  my_wasm_function
} from "../pkg";

ivnsch avatar Sep 07 '22 13:09 ivnsch

Having the same problem here... I'll let you know if I find a solution!

arvid220u avatar Sep 09 '22 19:09 arvid220u

@arvid220u it's fixed but I honestly don't know what it was. What I did included: overwriting manually the contents of src/pkg with the build contents, disabling manually the linters in wasm_bg.js and restarting. Now src/pkg seems to not update anymore? I'll update if there are new insights.

ivnsch avatar Sep 10 '22 08:09 ivnsch

Hey @arvid220u, @ivanschuetz! Please check rust-wasmpack-loader pacakge, it should fix your porblem.

yeskiy avatar Jul 19 '23 11:07 yeskiy