Skip to content

Commit 1fab348

Browse files
authored
fix(ext/node): attach register as static on Module (#34305)
Tools like tsx do `import M from "node:module"; M.register` to decide whether the host supports module loader hooks. The named `register` export (a stub that returns `undefined`) was already present, but the revert and re-land of the module loader hooks stack lost the line that attaches it as a static on `Module`, so `M.register` came back as `undefined`. tsx then falls through to its `registerHooks` feature gate, which requires Node `>= 24.11.1` while Deno reports `24.2.0`, so it throws "This version of Node.js does not support module.register()". Re-attaching `Module.register = register;` next to`Module.registerHooks = registerHooks;` is enough to make the stub visible again and unblocks tsx.
1 parent f0ef190 commit 1fab348

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

ext/node/polyfills/01_require.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,7 @@ export function registerHooks(hooks) {
30943094
}
30953095

30963096
Module.registerHooks = registerHooks;
3097+
Module.register = register;
30973098

30983099
let initialized = false;
30993100

tests/unit_node/module_test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ Deno.test("[node/module register] is a function", () => {
110110
assertEquals(register("foo"), undefined);
111111
});
112112

113+
// Regression test: tsx and other tools probe `Module.register` (the default
114+
// export of `node:module`) to decide whether the host supports module loader
115+
// hooks. Make sure both `Module.register` and `Module.registerHooks` are
116+
// attached as static methods so `import M from "node:module"; M.register`
117+
// resolves to the stub instead of `undefined`.
118+
Deno.test("[node/module] Module.register and Module.registerHooks are exposed", () => {
119+
// @ts-ignore Not in our bundled @types/node yet.
120+
assertEquals(typeof Module.register, "function");
121+
// @ts-ignore Not in our bundled @types/node yet.
122+
assertEquals(typeof Module.registerHooks, "function");
123+
// @ts-ignore Stub returns undefined.
124+
assertEquals(Module.register("foo"), undefined);
125+
});
126+
113127
Deno.test("[node/module] overriding Module._compile is possible and Node globals work", () => {
114128
// @ts-ignore Not documented but available
115129
const originalCompile = Module.prototype._compile;

0 commit comments

Comments
 (0)