First of all, I would like to apologize if this is not the right place to ask for help to solve this issue. I'm a browserify user, and since I have problems just with a file create by emscripten, I assume the problem might live here.
Long story short, I'm importing an emscripten module in the frontend using browserify. At execution time, the module exists, but empty.
You can reproduce the issue as follows (requires emcc and browserify installed system wide):
emcc main.cpp -o main.js -s EXPORTED_FUNCTIONS="['_int_sqrt']"browserify index.js > bundle.jsI've already tested that the generated code is correct: running in a node environment, works as expected (there is a demonstration using mocha here
PD: I have the same test case, but with a more elaborated toolchain in this repo with a readme to reproduce all the steps
module.exports is set only when ENVIRONMENT_IS_NODE is true, and it won't be true if ENVIRONMENT_IS_WEB is true:
ENVIRONMENT_IS_WEB = typeof window === 'object';
ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function' && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
I think it would be best to always set module.exports (if module exists etc), like it does for MODULARIZE.
Turning MODULARIZE on will probably help you @txusinho, but you will need to access the exported functions differently.
@curiousdannii I appreciate your help, and the speed! The solution worked perfect on my side, and I'm able to use module as needed. The access to functions is not a problem if I have possibilities to access the Module element.
I made this question also in stackoverflow, I'll update the answer there so anyone with the same problem can come to a solution.
EDIT: Sorry for coming back, but after inspecting the code generated, I can't find in the instance of Module any reference to the function described. Is there something I might be missing?
EDIT 2: I replaced the flag instead of adding it. Forget what I said
Most helpful comment
module.exports is set only when ENVIRONMENT_IS_NODE is true, and it won't be true if ENVIRONMENT_IS_WEB is true:
I think it would be best to always set module.exports (if module exists etc), like it does for MODULARIZE.
Turning MODULARIZE on will probably help you @txusinho, but you will need to access the exported functions differently.