user12658460
user12658460

Reputation:

Module not defined error when trying to run a wasm function

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.

Upvotes: 1

Views: 1609

Answers (2)

Alex Dawn
Alex Dawn

Reputation: 55

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.

Upvotes: 0

Andy Mardell
Andy Mardell

Reputation: 1191

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

Upvotes: 0

Related Questions