Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! module: handle null source from async loader hooks in sync hooks
  • Loading branch information
joyeecheung committed Oct 8, 2025
commit 790b5f46d0af38fb4dfa0ea817405890a06b2c76
4 changes: 1 addition & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,9 +1794,7 @@ function loadSource(mod, filename, formatFromNode) {

const defaultLoad = getDefaultLoad(mod[kURL], filename);
const loadResult = loadWithHooks(mod[kURL], mod[kFormat], /* importAttributes */ undefined,
getCjsConditionsArray(),
defaultLoad,
validateLoadStrict);
getCjsConditionsArray(), defaultLoad, validateLoadStrict);
// Reset the module properties with load hook results.
if (loadResult.format !== undefined) {
mod[kFormat] = loadResult.format;
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/modules/customization_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function validateLoadStrict(url, context, result) {
}

function validateLoadSloppy(url, context, result) {
validateSourceSloppy(url, context, result);
validateSourcePermissive(url, context, result);
validateFormat(url, context, result);
return result;
}
Expand All @@ -299,11 +299,12 @@ function validateSourceStrict(url, context, result) {
}
}

function validateSourceSloppy(url, context, result) {
function validateSourcePermissive(url, context, result) {
const { source, format } = result;
if (format === 'commonjs' && source == null) {
// Accommodate the quirk in defaultLoad used by asynchronous loader hooks
// which sets source to null for commonjs.
Comment thread
joyeecheung marked this conversation as resolved.
// See: https://github.com/nodejs/node/issues/57327#issuecomment-2701382020
return;
}
validateSourceStrict(url, context, result);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ translators.set('commonjs', function commonjsStrategy(url, translateContext, par
}

// For backward-compatibility, it's possible to return a nullish value for
// CJS source associated with a file: URL - that usually means the source is not
// CJS source associated with a `file:` URL - that usually means the source is not
// customized (is loaded by default load) or the hook author wants it to be reloaded
// through CJS routine. In this case, the source is obtained by calling the
// monkey-patchable CJS loader.
Expand Down
Loading