diff --git a/lib/internal/modules/esm/hooks.js b/lib/internal/modules/esm/hooks.js index 5984c707f16c4f..4571922ed5a0e9 100644 --- a/lib/internal/modules/esm/hooks.js +++ b/lib/internal/modules/esm/hooks.js @@ -237,7 +237,7 @@ class Hooks { const nextResolve = nextHookFactory(chain[chain.length - 1], meta, { validateArgs, validateOutput }); - const resolution = await nextResolve(originalSpecifier, context); + const resolution = await nextResolve(originalSpecifier, defineImportAssertionAlias(context)); const { hookErrIdentifier } = meta; // Retrieve the value after all settled validateOutput(hookErrIdentifier, resolution); diff --git a/test/es-module/test-esm-import-assertion-warning.mjs b/test/es-module/test-esm-import-assertion-warning.mjs index a11b5164cebffc..0cdb21c7ee838b 100644 --- a/test/es-module/test-esm-import-assertion-warning.mjs +++ b/test/es-module/test-esm-import-assertion-warning.mjs @@ -7,6 +7,11 @@ await Promise.all([ `data:text/javascript,export ${encodeURIComponent(function resolve() { return { shortCircuit: true, url: 'data:application/json,1', importAssertions: { type: 'json' } }; })}`, + // Using importAssertions on the context object of the resolve hook should warn but still work. + `data:text/javascript,export ${encodeURIComponent(function resolve(s, c, n) { + const type = c.importAssertions.type; + return { shortCircuit: true, url: 'data:application/json,1', importAttributes: { type: 'json' } }; + })}`, // Setting importAssertions on the context object of the load hook should warn but still work. `data:text/javascript,export ${encodeURIComponent(function load(u, c, n) { c.importAssertions = { type: 'json' }; @@ -22,9 +27,9 @@ await Promise.all([ '--eval', ` import assert from 'node:assert'; import { register } from 'node:module'; - + register(${JSON.stringify(loaderURL)}); - + assert.deepStrictEqual( { ...await import('data:') }, { default: 1 }