-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Description
Version
22.15.0
Platform
Darwin TK46XHNX04 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
const { registerHooks } = require('node:module')
registerHooks({
resolve: (specifier, context, nextResolve) => {
console.log(`Resolving specifier: ${specifier}`);
return nextResolve(specifier, context);
},
load: (url, context, nextLoad) => {
console.log(`Loading URL: ${url}`);
debugger
return nextLoad(url, context);
}
})
node -r ./loader-hook.js -e "require('node:test')"
How often does it reproduce? Is there a required condition?
This happens for all the schemeless builtins
const schemelessBlockList = new SafeSet([
'sea',
'sqlite',
'quic',
'test',
'test/reporters',
]);
What is the expected behavior? Why is that the expected behavior?
The resolve/loader hooks do not crash
What do you see instead?
❯ node -r ./loader-hook.js -e "require('node:sea')"
Resolving specifier: module
Loading URL: node:module
Resolving specifier: node:sea
Loading URL: sea
node:internal/modules/customization_hooks:276
throw new ERR_INVALID_RETURN_PROPERTY_VALUE(
^
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.
at validateLoad (node:internal/modules/customization_hooks:276:11)
at nextStep (node:internal/modules/customization_hooks:190:14)
at load (/Users/revans/loader-hook.js:14:12)
at nextStep (node:internal/modules/customization_hooks:185:26)
at loadWithHooks (node:internal/modules/customization_hooks:348:18)
at loadBuiltinWithHooks (node:internal/modules/cjs/loader:1164:24)
at Function._load (node:internal/modules/cjs/loader:1216:20)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
at Module.require (node:internal/modules/cjs/loader:1487:12) {
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'
}
Node.js v22.15.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
convertCJSFilenameToURL
#58612joyeecheung commentedon Jun 7, 2025
I won’t have time to get back to the computer until next Monday, but it looks like it’s the URL that gets passed into the hooks that should be fixed - it should’ve been node:sea instead of sea, and the non-prefixed one isn’t really an URL so it should’ve fail the validation. The CJS loader internally uses filename and IDs for performance and compatibility everywhere and only convert them into URLs for the hooks when there are hooks, so it seems somewhere the conversion is missed before it goes into the hooks.
To workaround it before the missed conversion is fixed you can prefix the ones that need the scheme with node: manually in the load hook for now.
himself65 commentedon Jun 7, 2025
node/lib/internal/modules/cjs/loader.js
Lines 1051 to 1055 in 705bcc2
Seems like issue from here,
normalizeRequirableId
will translate likenode:sea
tosea
himself65 commentedon Jun 7, 2025
BuiltinModule.canBeRequiredByUsers(StringPrototypeSlice(id, 5))
is always false for those modulemodule: convert schema-only core module on `convertCJSFilenameToURL`
module: convert schema-only core module on `convertCJSFilenameToURL`
module: convert schema-only core module on `convertCJSFilenameToURL`
module: convert schema-only core module on `convertCJSFilenameToURL`