diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 7da68dc05e84b4..34fe20b18ad4d8 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -8,7 +8,6 @@ const { markBootstrapComplete } = require('internal/process/pre_execution'); -const esmLoader = require('internal/process/esm_loader'); const { evalScript } = require('internal/process/execution'); @@ -34,6 +33,7 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) { process.exit(1); } + const esmLoader = require('internal/process/esm_loader'); esmLoader.loadESM(() => { console.log(`Welcome to Node.js ${process.version}.\n` + 'Type ".help" for more information.'); diff --git a/test/parallel/test-repl-built-in-modules.js b/test/parallel/test-repl-built-in-modules.js index b1845d83e68332..6273367e65a2a7 100644 --- a/test/parallel/test-repl-built-in-modules.js +++ b/test/parallel/test-repl-built-in-modules.js @@ -30,3 +30,19 @@ assert.doesNotMatch( stdout, /Uncaught Error: Cannot find module 'wasi'[\w\W]+- \n/); assert.match(stdout, /{ WASI: \[class WASI\] }/); + +{ + const res = cp.execFileSync(process.execPath, ['-i'], { + input: "'wasi' in global", + encoding: 'utf8', + }); + // `wasi` shouldn't be defined on global when the flag is not set + assert.match(res, /false\n/); +} +{ + const res = cp.execFileSync(process.execPath, ['-i', '--experimental-wasi-unstable-preview1'], { + input: "'wasi' in global", + encoding: 'utf8', + }); + assert.match(res, /true\n/); +}