Repository navigation
feat: use module.registerHooks() instead of deprecated module.register() - #19
Merged
Merged
Conversation
Node.js 26 emits a runtime deprecation (DEP0205) for module.register(). hot.init() now registers synchronous in-thread hooks with module.registerHooks() on Node.js >= 22.22.3, 24.11.1, 25.1.0 and 26, and falls back to module.register() on older versions, whose registerHooks() breaks CommonJS loading when combined with module.register() hooks such as ts-node's. The same HotHookLoader serves both modes. With in-thread hooks, the chokidar watcher runs in a dedicated worker so it neither keeps the process alive nor misses changes during startup. Closes #18 Amp-Thread-ID: https://ampcode.com/threads/T-01a1b212-dc0a-7380-bad5-624903b77b96
c8 10 depends on yargs 17.7.2, which fails to load on Node.js 26
("require is not defined in ES module scope").
Amp-Thread-ID: https://ampcode.com/threads/T-01a1b212-dc0a-7380-bad5-624903b77b96
Julien-R44
force-pushed
the
feat/sync-module-hooks
branch
from
November 6, 2026 21:34
dffc8e6 to
4aa8428
Compare
Julien-R44
changed the base branch from
main
to
fix/import-meta-hot-injection
November 6, 2026 21:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18
Why
Node.js 26 emits a runtime deprecation for
module.register()(DEP0205), and it will be removed in a future version.hot.init()called it, so every app using hot-hook printed the warning on Node 26.What changes
hot.init()registers synchronous, in-thread hooks withmodule.registerHooks()on Node.js >= 22.22.3, 24.11.1, 25.1.0 and 26.module.register().registerHooks()exists since 22.15, but before those versions a syncloadhook crashes on CommonJS (ERR_INVALID_RETURN_PROPERTY_VALUE) as soon as anymodule.register()hook is also registered (ts-node, older tsx,@poppinss/ts-exectriggers it too). The thresholds were bisected on official binaries and match tsx 4.23's own.HotHookLoaderserves both modes.resolve/loadare no longerasync; a smallthen()helper (maybe_async.ts) stays synchronous whennextResolve/nextLoadreturn plain objects and chains otherwise.DynamicImportCheckeris now sync (readFileSync+parseImportsSync).watcher_thread.ts). On the main thread it kept the process alive and missed changes made right after startup. The worker is unref'd after its initial scan,hot.init()waits for that scan, and worker errors or an early exit can't block init.loadcopiescontextinstead of deletingimportAttributes.hot(frozen in-thread), and decodessourceexplicitly: with an async loader in the chain it is aUint8Array, andtoString()produced comma-separated bytes, so the entrypoint silently did nothing.Behaviour change: with in-thread hooks,
require()calls also go through hot-hook (noted in the changeset).Verification
Note
Stacked on #20, which fixes the
import.meta.hotinjection regression fromed28a8c(AdonisJS controllers stopped hot reloading). Merge #20 first. With in-thread hooks, hot-hook wraps the TS loader's output, so the inline source map shift from #20 also applies to@poppinss/ts-exec(Adonis 7): line-1 positions with--enable-source-mapsare identical with and without hot-hook on Node 26.pnpm quick:test: 31/31 (with fix: inject import.meta.hot into every module using import.meta #20) on Node 22.14, 22.15, 22.22.3, 24.11.1, 24.22.2 and 26.12.1. New tests: the process exits without DEP0205 (fails on main), and HMR works after amodule.register()loader (fails without thesourcedecoding fix).create-adonisjsapps with this build installed, drivingnode ace serve --hmr: boot, HMR on a controller, on a service it imports and a second edit, runtime error then recovery, full reload onstart/routes.ts, restart on.env, HMR after restart.Not tested: Windows and macOS (CI covers Windows).