I'm currently using Emscripten to compile a basic C function into JavaScript to use within a React Native project. However, when I import Module
from inside React code, the Module object is empty. This occurs in both React and React Native projects.
Running index.js
in my terminal with node ./index.js
returns the expected result.
I'm compiling ping.c and outputting ping.js with this command:
emcc ping.c -o ping.js -s WASM=0 -s EXPORTED_FUNCTIONS='["_pingIt"]'
ping.c:
#include <stdio.h>
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
int pingIt() {
return 1;
}
index.js:
let Module = require('./ping.js');
module.exports = Module;
I'm exporting Module from index.js
and importing it into my React code.
Current behavior
// Running in React
console.log(Module); // returns {}
Expected behavior
// Running in React
console.log(Module._pingIt()); // should return 1