diff --git a/src/shell.js b/src/shell.js index 789de77778b9f..74d1410473511 100644 --- a/src/shell.js +++ b/src/shell.js @@ -111,9 +111,12 @@ if (ENVIRONMENT_IS_NODE) { Module['arguments'] = process['argv'].slice(2); + // MODULARIZE == 1 will export the module in the proper place outside, we don't need to export here +#if MODULARIZE == 0 if (typeof module !== 'undefined') { module['exports'] = Module; } +#endif #if NODEJS_CATCH_EXIT process['on']('uncaughtException', function(ex) { diff --git a/tests/test_other.py b/tests/test_other.py index be6b33e1c9959..5c0fd0f52ec88 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -5438,6 +5438,10 @@ def test_require_modularize(self): assert "module['exports'] = NotModule;" in src output = Popen(NODE_JS + ['-e', 'var m = require("./a.out.js"); m();'], stdout=PIPE, stderr=PIPE).communicate() assert output == ('hello, world!\n', ''), 'expected output, got\n===\nSTDOUT\n%s\n===\nSTDERR\n%s\n===\n' % output + Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'MODULARIZE=1', '-s', 'NO_EXIT_RUNTIME=1']).communicate() + # We call require() twice to ensure it returns wrapper function each time + output = Popen(NODE_JS + ['-e', 'require("./a.out.js")();var m = require("./a.out.js"); m();'], stdout=PIPE, stderr=PIPE).communicate() + assert output[0] == 'hello, world!\nhello, world!\n', 'expected output, got\n===\nSTDOUT\n%s\n===\nSTDERR\n%s\n===\n' % output def test_native_optimizer(self): def test(args, expected):