From 698e21b34618d5a464df2b04f4838183675348bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Fri, 29 Nov 2019 16:30:25 -0500 Subject: [PATCH] lib: add warning on dynamic import es modules PR-URL: https://github.com/nodejs/node/pull/30720 Backport-PR-URL: https://github.com/nodejs/node/pull/33055 Reviewed-By: Guy Bedford --- lib/internal/process/esm_loader.js | 6 ++++++ test/es-module/test-esm-dynamic-import.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 53302f75baa669..cca1e3e07956a1 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -24,6 +24,12 @@ exports.initializeImportMetaObject = function(wrap, meta) { exports.importModuleDynamicallyCallback = async function(wrap, specifier) { assert(calledInitialize === true || !userLoader); + if (!calledInitialize) { + process.emitWarning( + 'The ESM module loader is experimental.', + 'ExperimentalWarning', undefined); + calledInitialize = true; + } const { callbackMap } = internalBinding('module_wrap'); if (callbackMap.has(wrap)) { const { importModuleDynamically } = callbackMap.get(wrap); diff --git a/test/es-module/test-esm-dynamic-import.js b/test/es-module/test-esm-dynamic-import.js index e72922d31c0b18..e01b86eed143ed 100644 --- a/test/es-module/test-esm-dynamic-import.js +++ b/test/es-module/test-esm-dynamic-import.js @@ -42,6 +42,9 @@ function expectFsNamespace(result) { // For direct use of import expressions inside of CJS or ES modules, including // via eval, all kinds of specifiers should work without issue. (function testScriptOrModuleImport() { + common.expectWarning('ExperimentalWarning', + 'The ESM module loader is experimental.'); + // Importing another file, both direct & via eval // expectOkNamespace(import(relativePath)); expectOkNamespace(eval(`import("${relativePath}")`));