mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
committed by
Guy Bedford
parent
aa363c49ea
commit
6669cd138e
@@ -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);
|
||||
|
||||
@@ -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}")`));
|
||||
|
||||
Reference in New Issue
Block a user