lib: add warning on dynamic import es modules

PR-URL: https://github.com/nodejs/node/pull/30720
Reviewed-By: Guy Bedford <guybedford@gmail.com>
This commit is contained in:
Juan José Arboleda
2019-11-29 16:30:25 -05:00
committed by Guy Bedford
parent aa363c49ea
commit 6669cd138e
2 changed files with 9 additions and 0 deletions

View File

@@ -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);

View File

@@ -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}")`));