You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This produces a web page that does not run, but gives no build errors either.
There are two things that are odd about the generated build.
First, I think the history of -s MODULARIZE=1 was intended to be primarily used when building to JavaScript with -o a.js, so the intent is that one would manually invoke the generate Module() function (defined with -s EXPORT_NAME= option) to start the app. But when one is targeting HTML with any of the default html shell files that Emscripten provides (no --shell-file directive passed, or --shell-file src/shell_minimal.html) it seems that we should be automatically be generating a Module(); invocation there to start the page.
Second, why is the default value of the -s EXPORT_NAME= option called Module? That seems wrong. Module is supposed to be an object that contains import/export interactions with the generated page. In MODULARIZE mode EXPORT_NAME specifies the name of the function that one should call to launch the page. Calling this function also Module seems like we are calling two different things by the same name, and by default, one would need to call Module(Module); to run the page. Hence when building
it is not possible to launch the generated build even from web console.
Perhaps default value of EXPORT_NAME should be changed to something like 'EmscriptenCode', so that the default launch sequence would look like EmscriptenCode(Module);, and our default shells would add a {{{ EXPORT_NAME }}}(Module); directive to them?
// page, it will use the global scope. With MODULARIZE set, we will instead emit
//
// var EXPORT_NAME = function(Module) {
// Module = Module || {};
// // .. all the emitted code from emscripten ..
// return Module;
// };
//
// where EXPORT_NAME is from the option of the same name
However if I do a -s MODULARIZE=1 -s EXPORT_NAME='EmscriptenCode' build, then I don't get
varEmscriptenCode=function(Module){Module=Module||{};// .. all the emitted code from emscripten ..returnModule;};
MODULARIZE by itself does not run the code, yes - intentionally, so you can instantiate it multiple times later as needed.
MODULARIZE_INSTANCE will create an instance for you, and call it (so you can't create more than one).
About the name being replaced in more places - yeah, that might be redundant, maybe we did it for aesthetic purposes. I'm not sure - may need to look through the PRs.
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
See this is closed, but still a little confused, not being a JS expert. If I build with -s MODULARIZE=1 -s EXPORT_NAME='"createModule"' -s MODULARIZE_INSTANCE=1 --shell-file "shell_minimal.html" in the HTML there is an object created called Module :
@yowl note that MODULARIZE_INSTANCE was recently removed. it did lead to complicated situations like this one. You can do similar things by manually creating an instance, which avoids the possible confusion between the generator function (createModule in your example) and the parameters to that function, which are Module in that shell file.
In general I think the default html shell files just set values to Module, so they are not aware of MODULARIZE or EXPORT_NAME - you may need a custom html in some cases.
Activity
juj commentedon Jan 29, 2019
Hmm, further, docs in settings.js say
However if I do a
-s MODULARIZE=1 -s EXPORT_NAME='EmscriptenCode'build, then I don't getin my build. But instead I get
which seems unnecessary - the inner
Moduleshould not need to change toEmscriptenCode?kripken commentedon Jan 29, 2019
MODULARIZEby itself does not run the code, yes - intentionally, so you can instantiate it multiple times later as needed.MODULARIZE_INSTANCEwill create an instance for you, and call it (so you can't create more than one).About the name being replaced in more places - yeah, that might be redundant, maybe we did it for aesthetic purposes. I'm not sure - may need to look through the PRs.
stale commentedon Jan 29, 2020
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
yowl commentedon May 17, 2020
See this is closed, but still a little confused, not being a JS expert. If I build with
-s MODULARIZE=1 -s EXPORT_NAME='"createModule"' -s MODULARIZE_INSTANCE=1 --shell-file "shell_minimal.html"in the HTML there is an object created calledModule:but I dont think it gets used at
Would I be right in saying that
Modulecreated inshell_minimal.htmlis not usedModulecreated inshell_minimal.htmlI should drop-s MODULARIZE_INSTANCE=1and pass it in tocreateModulee.g.Which I could put in
shell_minimal.html?kripken commentedon May 18, 2020
@yowl note that
MODULARIZE_INSTANCEwas recently removed. it did lead to complicated situations like this one. You can do similar things by manually creating an instance, which avoids the possible confusion between the generator function (createModulein your example) and the parameters to that function, which areModulein that shell file.In general I think the default html shell files just set values to
Module, so they are not aware ofMODULARIZEorEXPORT_NAME- you may need a custom html in some cases.Fix -sMODULARIZE + html output. NFC
Fix -sMODULARIZE + html output. NFC
Fix -sMODULARIZE + html output. NFC (#26173)
Fix -sMODULARIZE + html output. NFC (emscripten-core#26173)