MCPcopy Index your code
hub / github.com/nodejs/node / import

Method import

lib/internal/modules/esm/loader.js:630–653  ·  view source on GitHub ↗

* This method is usually called indirectly as part of the loading processes. * Use directly with caution. * @param {string} specifier The first parameter of an `import()` expression. * @param {string} parentURL Path of the parent importing the module. * @param {Record } im

(specifier, parentURL, importAttributes, phase = kEvaluationPhase, isEntryPoint = false)

Source from the content-addressed store, hash-verified

628 * @returns {Promise<ModuleExports>}
629 */
630 async import(specifier, parentURL, importAttributes, phase = kEvaluationPhase, isEntryPoint = false) {
631 return onImport.tracePromise(async () => {
632 const request = { specifier, phase, attributes: importAttributes, __proto__: null };
633 let moduleJob;
634 try {
635 moduleJob = await this.getOrCreateModuleJob(parentURL, request);
636 } catch (e) {
637 if (e?.code === 'ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED') {
638 return new Promise(() => {});
639 }
640 throw e;
641 }
642 if (phase === kSourcePhase) {
643 const module = await moduleJob.modulePromise;
644 return module.getModuleSourceObject();
645 }
646 const { module } = await moduleJob.run(isEntryPoint);
647 return module.getNamespace();
648 }, {
649 __proto__: null,
650 parentURL,
651 url: specifier,
652 });
653 }
654
655 /**
656 * @see {@link AsyncLoaderHooks.register}

Callers 15

executeUserEntryPointFunction · 0.80
registerMethod · 0.80
loadESMFromCJSFunction · 0.80
runFunction · 0.80
getReportersMapFunction · 0.80
worker_thread.jsFile · 0.80
importModuleDynamicallyFunction · 0.80

Calls 3

getOrCreateModuleJobMethod · 0.95
tracePromiseMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected