Skip to content

Commit 233b988

Browse files
juanarboltargos
authored andcommitted
lib: add warning on dynamic import es modules
PR-URL: #30720 Backport-PR-URL: #33055 Reviewed-By: Guy Bedford <[email protected]>
1 parent f9edab1 commit 233b988

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/internal/process/esm_loader.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ exports.initializeImportMetaObject = function(wrap, meta) {
2424

2525
exports.importModuleDynamicallyCallback = async function(wrap, specifier) {
2626
assert(calledInitialize === true || !userLoader);
27+
if (!calledInitialize) {
28+
process.emitWarning(
29+
'The ESM module loader is experimental.',
30+
'ExperimentalWarning', undefined);
31+
calledInitialize = true;
32+
}
2733
const { callbackMap } = internalBinding('module_wrap');
2834
if (callbackMap.has(wrap)) {
2935
const { importModuleDynamically } = callbackMap.get(wrap);

test/es-module/test-esm-dynamic-import.js

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ function expectFsNamespace(result) {
4242
// For direct use of import expressions inside of CJS or ES modules, including
4343
// via eval, all kinds of specifiers should work without issue.
4444
(function testScriptOrModuleImport() {
45+
common.expectWarning('ExperimentalWarning',
46+
'The ESM module loader is experimental.');
47+
4548
// Importing another file, both direct & via eval
4649
// expectOkNamespace(import(relativePath));
4750
expectOkNamespace(eval(`import("${relativePath}")`));

0 commit comments

Comments
 (0)