Skip to content

tests: module-hooks load hook returning null causes ERR_INVALID_RETURN_PROPERTY_VALUE #60685

@THE-Amrit-mahto-05

Description

@THE-Amrit-mahto-05

Version

v24.5.0

Platform

Darwin MacBook-Pro-M1.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000 arm64

Subsystem

test / module-hooks

What steps will reproduce the bug?

  1. Navigate to the test directory:
    cd node/test/module-hooks

  2. Run the test:
    node test-module-hooks-load-async-and-sync.js

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

The test should complete successfully with exit code 0.

What do you see instead?

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected a string, an ArrayBuffer, or a TypedArray to be returned for the "source" from the "load" hook but got null.

Additional information

Root cause:

  • In fixtures/module-hooks/sync-and-async/async-forward-loader.js and sync-forward.js,
    the load hooks directly return nextLoad(url, context), which can return null.

  • This causes ERR_INVALID_RETURN_PROPERTY_VALUE when the loader chain doesn't provide a result.

Proposed fix:
Add a fallback when nextLoad returns null:
{
format: 'esm',
source: 'console.log("Hello world");'
}

After adding this fallback, the test runs successfully:
node test-module-hooks-load-async-and-sync.js
echo $?

Output: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions