1

I am reading this article on getting started with web assembly. I tried to write my code in js but when I run it I get this error in the client side console:

Uncaught ReferenceError: Module is not defined

My test.cpp file looks like this

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

int test() {
  return 0;
}

My index.html file looks like this

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

my app.js file looks lime this

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/'));

I start the process with node app but when I load localhost it gives me that error in my console.

2 Answers 2

0

You're trying to call a function which doesn't exist (Module.cwrap())

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

Removing the above lines from your code will fix your current error

Sign up to request clarification or add additional context in comments.

1 Comment

If I do not use that code, how can I call the wasm function?
0

I'm going through the same tutorial, if you peek at the generated .js code from the previous example, module.cwrap is generated by that. If you want to use your own html you need to import the generated js or use the --shell-file flag with your html file as a template.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.