首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将WebAssembly锈菌导入NextJS?

如何将WebAssembly锈菌导入NextJS?
EN

Stack Overflow用户
提问于 2021-09-08 01:23:57
回答 1查看 1.3K关注 0票数 3

我使用的是nextjs,我使用的是:

代码语言:javascript
运行
复制
import { greet } from "backend";

这是package.json依赖项:

代码语言:javascript
运行
复制
"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上的配置

代码语言:javascript
运行
复制
module.exports = { 
reactStrictMode: true,
experiments: { asyncWebAssembly: true, buildHttp: true, executeModule: true, layers: true, lazyCompilation: true, outputModule: true, syncWebAssembly: true, topLevelAwait: true, },
}

这是我的错误:

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2022-01-04 02:52:57

您需要编辑next.config.js

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

以下是我的next.config.js文件的内容

代码语言:javascript
运行
复制
module.exports = {
    reactStrictMode: true,
    webpack: function (config, options) {
        config.experiments = { asyncWebAssembly: true };
        return config;
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69095975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档