fix: migrate from deprecated module.register() to module.registerHooks()#585
fix: migrate from deprecated module.register() to module.registerHooks()#585cjnoname wants to merge 1 commit into
Conversation
|
@Boshen This will trigger red warnings in the latest Node.js 25 and 26. If possible, could you please help release a fix as soon as possible? Thanks. |
module.register() has been runtime-deprecated as DEP0205 since Node.js v25.9.0. Use module.registerHooks() when available (Node.js >= 24.4), falling back to module.register() for older versions. The resolve hook wrapper strips fields (e.g. importAttributes) not recognized by the native createResolve binding to maintain compatibility.
6bde0c9 to
0ee4b66
Compare
|
Update: The Even stripping known extra fields in a JS wrapper isn't sufficient — The root cause is that To properly fix this, the Rust native In the meantime, a workaround is to suppress the deprecation warning by temporarily patching const _emitWarning = process.emitWarning;
process.emitWarning = (warning, ...args) => {
if (typeof warning === "string" && warning.includes("module.register()")) { return; }
return _emitWarning.call(process, warning, ...args);
};
register("@oxc-node/core/esm", import.meta.url);
process.emitWarning = _emitWarning;I'll close this PR since it's not the right fix. The proper solution requires changes to the native binding layer. |
Summary
module.register()has been runtime-deprecated as DEP0205 since Node.js v25.9.0 (see nodejs/node#62401), causing the following warning on every invocation:Changes
module.registerHooks()when available (Node.js >= 24.4), falling back tomodule.register()for older versionsresolvehook is wrapped to only passparentURLandconditionsto the nativecreateResolvebinding, stripping newer context fields (e.g.importAttributes) that the native binding doesn't recognizeinitTracing()is called directly in theregisterHooksbranch sinceesm.mjsis no longer imported in that pathNote for maintainers
This workaround strips unknown fields from the resolve context before passing to the native binding. A more robust long-term fix would be to update the Rust
createResolveimplementation to either:#[napi(object)]with#[serde(flatten)]or similar), orimportAttributes(and any future fields Node.js adds to the resolve context)This would make the native binding forward-compatible with future Node.js versions without needing a JS wrapper.