diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 81002a3e3c49f6..67fcfc8fbf172f 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -402,11 +402,10 @@ function initializePolicy() { } function initializeWASI() { - if (getOptionValue('--experimental-wasi-unstable-preview0')) { - const { NativeModule } = require('internal/bootstrap/loaders'); - const mod = NativeModule.map.get('wasi'); - mod.canBeRequiredByUsers = true; - } + const { NativeModule } = require('internal/bootstrap/loaders'); + const mod = NativeModule.map.get('wasi'); + mod.canBeRequiredByUsers = + getOptionValue('--experimental-wasi-unstable-preview0'); } function initializeCJSLoader() { diff --git a/src/node_native_module.cc b/src/node_native_module.cc index 814adb620dcf8a..43c13ea30a0dc5 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -98,6 +98,7 @@ void NativeModuleLoader::InitializeModuleCategories() { #endif // !HAVE_OPENSSL "sys", // Deprecated. + "wasi", // Experimental. "internal/test/binding", "internal/v8_prof_polyfill", "internal/v8_prof_processor", diff --git a/test/wasi/test-wasi-require-flag.js b/test/wasi/test-wasi-require-flag.js new file mode 100644 index 00000000000000..0a52ea952d2785 --- /dev/null +++ b/test/wasi/test-wasi-require-flag.js @@ -0,0 +1,9 @@ +'use strict'; +// This test verifies that the WASI module cannot be require()'ed without a +// CLI flag while it is still experimental. +require('../common'); +const assert = require('assert'); + +assert.throws(() => { + require('wasi'); +}, /^Error: Cannot find module 'wasi'/);