1

I'm trying to migrate my site to mdx2 and mdx-embed. I'm running into issues with webpack not recognizing my web-assembly configuration in next.config.mjs. The issue is happening during the import of wasm file during the "yarn build".

Import trace for requested module:
./wasm/fulltext-search/pkg/fulltext_search_core.js
./components/Search/Search.tsx
./components/Search/index.tsx
./pages/articles/index.tsx

Here is my migration branch below:

https://github.com/hanymorcos/hanymorcos.github.io/tree/next_config_mjs_mdx2

info  - Creating an optimized production build  
Failed to compile.

./wasm/fulltext-search/pkg/fulltext_search_core_bg.wasm
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)
Hany Morcos
  • 147
  • 1
  • 5

1 Answers1

-1

You have to add the configuration to enable WebAssembly under the webpack configuration, not in Next.js configuration object root.

module.exports = {
    // Your other Next.js configs

    webpack: function (config, { isServer }) {
        // Your other webpack configs

        config.experiments = { ...config.experiments, asyncWebAssembly: true }

        return config
    }
}

See the official Next.js WebAssembly example.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
  • Hi thank you for replying. it didnt' work. I've been trying stuff out for the last 24 hours and not difference. https://github.com/hanymorcos/hanymorcos.github.io/blob/next_config_mjs_mdx2/next.config.mjs – Hany Morcos Aug 01 '22 at 17:33
  • Also, I'm not using commonjs, I'm using ES module. Because I want to configure mdx2. – Hany Morcos Aug 01 '22 at 17:35