I am trying to import a module generated with emscripten as a es6 module. I am trying with the basic example from emscripten doc.
This is the command I am using to generate the js module from the C module:
emcc example.cpp -o example.js -s EXPORTED_FUNCTIONS="['_int_sqrt']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap']" -s EXPORT_ES6=1 -s MODULARIZE=1
The C module :
#include <math.h>
extern "C" {
int int_sqrt(int x) {
return sqrt(x);
}
}
Then importing the generated js module:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Wasm example</title>
</head>
<body>
<script type="module">
import Module from './example.js'
int_sqrt = Module.cwrap('int_sqrt', 'number', ['number']);
console.log(int_sqrt(64));
</script>
</body>
</html>
This is failing because cwrap is not available on the Module object:
Uncaught TypeError: Module.cwrap is not a function