Repository navigation
ERR_INVALID_RETURN_PROPERTY_VALUE when using module.registerHooks #59384
Copy link
Copy link
Closed
Description
Version
22.18.0
Platform
Linux lttm77 6.1.43 #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Use this codesandbox and run yarn test.
How often does it reproduce? Is there a required condition?
When using --import option to override the load hook with registerHooks to ignore CSS files.
What is the expected behavior? Why is that the expected behavior?
Node should use the provided hook to ignore CSS imports. But the provided load hook never returns a null "source" so the error doesn't make any sense.
What do you see instead?
The following stacktrace with node 22.16.0 or 22.18.0:
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 undefined.
at validateLoad (node:internal/modules/customization_hooks:276:11)
at nextStep (node:internal/modules/customization_hooks:190:14)
at load (file:///project/workspace/tests/node-ignore-css.mjs:8:12)
at nextStep (node:internal/modules/customization_hooks:185:26)
at loadWithHooks (node:internal/modules/customization_hooks:348:18)
at #loadSync (node:internal/modules/esm/loader:834:14)
at ModuleLoader.load (node:internal/modules/esm/loader:793:28)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:580:43)
at #createModuleJob (node:internal/modules/esm/loader:604:36)
at #getJobFromResolveResult (node:internal/modules/esm/loader:338:34) {
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'
}
Or this one with node 22.17.1:
node:internal/assert:17
throw new ERR_INTERNAL_ASSERTION(message);
^
Error [ERR_INTERNAL_ASSERTION]: Unexpected module status 3.
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
at Function.fail (node:internal/assert:17:9)
at ModuleJob.runSync (node:internal/modules/esm/module_job:317:12)
at require (node:internal/modules/esm/translators:149:9)
at Object.<anonymous> (/project/workspace/node_modules/playwright-core/lib/server/registry/browserFetcher.js:44:16)
at loadCJSModule (node:internal/modules/esm/translators:164:3)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:200:7)
at ModuleJob.runSync (node:internal/modules/esm/module_job:309:39)
at require (node:internal/modules/esm/translators:149:9)
at Object.<anonymous> (/project/workspace/node_modules/playwright-core/lib/server/registry/index.js:45:29)
at loadCJSModule (node:internal/modules/esm/translators:164:3) {
code: 'ERR_INTERNAL_ASSERTION'
}
Additional information
I'm trying to upgrade my React app from MUI-X 7 to 8. They introduced a CSS import that needs to be ignored (as discussed in mui/mui-x#17427) with the following code:
// node-ignore-css.js
// Needs to be loaded before your code runs:
// node --import ./node-ignore-css.js ./index.js
import { registerHooks } from 'node:module';
registerHooks({
load(url, context, nextLoad) {
if (url.endsWith('.css')) {
return { url, format: 'module', source: '', shortCircuit: true };
}
return nextLoad(url, context);
},
});I'm trying to run Playwright tests with this ignore config, but I'm getting the above error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
joyeecheung commentedon Aug 28, 2025
Can you minimize the reproduction a bit and share it as a github repository? It doesn't seem specific to playwright, for example, more likely that it's yarn that's injecting something into the module loading that doesn't play well with the hooks.
joyeecheung commentedon Sep 22, 2025
I am guessing this might be caused by the same caveat as #57327 (comment) because you use yarn which uses the
module.registerhooks that forcibly set the source of commonjs to null. #59929 might be enough to work around it.module: handle null source from async loader hooks in sync hooks
module: handle null source from async loader hooks in sync hooks
module: handle null source from async loader hooks in sync hooks
module: handle null source from async loader hooks in sync hooks
module: handle null source from async loader hooks in sync hooks
Document the registerHooks/Module._load broken-interplay phase