diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js index 9661bc716bfa76..13b286dc925772 100644 --- a/lib/internal/modules/esm/load.js +++ b/lib/internal/modules/esm/load.js @@ -29,13 +29,12 @@ const { * @param {ESModuleContext} context used to decorate error messages * @returns {Promise<{ responseURL: string, source: string | BufferView }>} */ -async function getSource(url, context) { +function getSource(url, context) { const { protocol, href } = url; const responseURL = href; let source; if (protocol === 'file:') { - const { readFile: readFileAsync } = require('internal/fs/promises').exports; - source = await readFileAsync(url); + source = readFileSync(url); } else if (protocol === 'data:') { const result = dataURLProcessor(url); if (result === 'failure') { @@ -80,7 +79,7 @@ function getSourceSync(url, context) { * @param {LoadContext} context * @returns {LoadReturn} */ -async function defaultLoad(url, context = kEmptyObject) { +function defaultLoad(url, context = kEmptyObject) { let responseURL = url; let { importAttributes, @@ -110,13 +109,13 @@ async function defaultLoad(url, context = kEmptyObject) { source = null; } else if (format !== 'commonjs') { if (source == null) { - ({ responseURL, source } = await getSource(urlInstance, context)); + ({ responseURL, source } = getSource(urlInstance, context)); context = { __proto__: context, source }; } if (format == null) { // Now that we have the source for the module, run `defaultGetFormat` to detect its format. - format = await defaultGetFormat(urlInstance, context); + format = defaultGetFormat(urlInstance, context); if (format === 'commonjs') { // For backward compatibility reasons, we need to discard the source in diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 493e9881a466c3..1f6b47857d0d93 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -804,9 +804,9 @@ class ModuleLoader { * if any. * @param {string} url The URL of the module to be loaded. * @param {object} context Metadata about the module - * @returns {Promise<{ format: ModuleFormat, source: ModuleSource }>} + * @returns {Promise<{ format: ModuleFormat, source: ModuleSource }> | { format: ModuleFormat, source: ModuleSource }} */ - async load(url, context) { + load(url, context) { if (loadHooks.length) { // Has module.registerHooks() hooks, use the synchronous variant that can handle both hooks. return this.#loadSync(url, context);