Next.js Discord

Discord Forum

Wasm library crashes by webpack, even though WASM support should be enabled

Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
African Slender-snouted CrocodileOP
Hello, I'm working inside Next.js 14 codebase and I need to use a wasm libray for some crypto logic, it's written in rust and uses wasm-pack, I've installed it from npm.

Now everywhere it says that I need to enable asyncWebAssembly for webpack in next.config.cjs, so I did.

webpack: function (config, options) {
    config.experiments = { asyncWebAssembly: true, layers: true };
    return config;
  },


But then when I import it as
import * as library from "library"

and try to use functions from it, webpack crashes with error:
Module parse failed: Unexpected character '' (1:0)
The module seem to be a WebAssembly module, but module is not flagged as WebAssembly module for webpack.
BREAKING CHANGE: Since webpack 5 WebAssembly is not enabled by default and flagged as experimental feature.
You need to enable one of the WebAssembly experiments via 'experiments.asyncWebAssembly: true' (based on async modules) or 'experiments.syncWebAssembly: true' (like webpack 4, deprecated).
For files that transpile to WebAssembly, make sure to set the module type in the 'module.rules' section of the config (e. g. 'type: "webassembly/async"').
(Source code omitted for this binary file)

0 Replies