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
If I'm not mistaken, this is expected behavior. In ES modules, imported modules are executed first (from bottom to top of the graph). The place of the import statements in the source code does not change that.
The relative order imports matters though. It means that you can have a third module that changes the global and import it before test.mjs, like so:
index.mjs has a dependency on test.mjs which by ECMA262 requires loading and evaluating test.mjs prior to beginning any evaluation of index.mjs. In particular imports are essentially hoisted to the top of a file. import is not imperative but being imperative was looked at in tc39/ecma262#368 .
Version: v9.8.0
Platform: Linux Host-002 4.14.6-300.fc27.x86_64 deps: update openssl to 1.0.1j #1 SMP Thu Dec 14 15:31:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Subsystem: esm
test.msj:
console.log( "global.TEST", global.TEST );
console.log( "process.env.TEST", process.env.TEST );
global.TEST2 = "yes";
process.env.TEST2 = "yes";
index.mjs:
global.TEST = "ok";
process.env.TEST = "ok";
import "./test";
console.log( "global.TEST2", global.TEST2 );
console.log( "process.env.TEST2", process.env.TEST2 );
$ node --experimental-modules ./index.mjs
global.TEST undefined
process.env.TEST undefined
global.TEST2 yes
process.env.TEST2 yes
Problem:
Imported module cannot access to global / process.env improvements while caller accesses to improvements done by imported module
Note:
Replacing import "./test" with import "./test?test=ok" doesn't provides an access to query parameters
The text was updated successfully, but these errors were encountered: