next.js - 如何将 WebAssembly rust 导入 NextJS?

标签 next.js webassembly

我正在使用 nextjs,我正在使用:

import { greet } from "backend";

这是 package.json 依赖项:

"dependencies": { "backend": "file:../backend/pkg", "next": "11.1.2", "react": "17.0.2", "react-dom": "17.0.2", "webpack": "^5.52.0" },

这是我在 nextjs.config.js 上的配置:

module.exports = { 
reactStrictMode: true,
experiments: { asyncWebAssembly: true, buildHttp: true, executeModule: true, layers: true, lazyCompilation: true, outputModule: true, syncWebAssembly: true, topLevelAwait: true, },
}

这是我的错误:

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)

最佳答案

您需要编辑next.config.js

https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config

这是我的 next.config.js 文件的内容

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

关于next.js - 如何将 WebAssembly rust 导入 NextJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69095975/

相关文章:

javascript - NextJS 动态列表在删除/更新时不更新

javascript - 转译 next.js 服务器代码

webpack - Web3 formatter.js 加载问题

javascript - Emscripten - 编译为 WASM 并在胶水代码中保留原始可调用函数名称

javascript - 如何将自定义 Memory 对象传递给 WebAssembly?

compiler-construction - 为什么 Wasm GC 设计要解决类型相等性、标记、子类型和方法等问题?

javascript - 如何在Next js上将数据从express服务器发送到客户端?

typescript - Nextjs 构建失败,错误为 'workerError'

javascript - 在 WebAssembly 中将数组作为参数传递时的线程安全性? [Emscripten]

webassembly - WASI 与 Web 程序集