gpt4 book ai didi

javascript - 尝试运行 wasm 函数时出现模块未定义错误

转载 作者:行者123 更新时间:2023-12-01 00:16:45 26 4
gpt4 key购买 nike

我正在阅读this有关 Web 组装入门的文章。我尝试用 js 编写代码,但是当我运行它时,我在客户端控制台中收到此错误:

Uncaught ReferenceError: Module is not defined

我的 test.cpp 文件如下所示

#include <stdio.h>
#include <iostream>
using namespace std;

int test() {
return 0;
}

我的 index.html 文件如下所示

<!DOCTYPE html>
<html>
<!-- My Html Stuff -->
<script>
var testFunc = Module.cwrap(
'test',
null,
null
);
testFunc();
<script>
</html>

我的 app.js 文件看起来很石灰

const http = require('http')
, express = require('express')
, app = express()
, server = http.createServer(app);

server.listen(process.env.PORT || 80);

app.use(express.static(__dirname + '/views/'));

我使用node app启动该过程,但是当我加载localhost时,它在我的控制台中给出了该错误。

最佳答案

您正在尝试调用一个不存在的函数 (Module.cwrap())

var testFunc = Module.cwrap(
'test',
null,
null
);
testFunc();

从代码中删除上述行将修复当前错误

关于javascript - 尝试运行 wasm 函数时出现模块未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59706549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com