Conversation
module.register() is deprecated as of Node 26 and warns once per process that replaces an ES module without --loader. Use module.registerHooks() (synchronous, in-thread) instead when it's safe to: - registerHooks() also intercepts CommonJS require(), which register() never did, so the sync resolve hook skips resolutions whose context.conditions includes "require". - registerHooks() exists on Node 22.15+/23.5+, but a Node bug (fixed in 22.23, 24.12, 25.2 and 26.0) means a sync hook can't be combined with an off-thread loader (--loader, tsx, ts-node, ...) once ESM imports CommonJS. So registerHooks() is only used where register() doesn't exist at all, or on Node 26+. - canRegisterLoader() now returns true if either API exists. Extracted the plan/resolve/load decision logic shared by the existing async hooks (quibble.mjs) and the new sync hooks (quibble-sync-hooks.js) into its own module. What's left un-shared, because it's genuinely specific to one style of hook: - the sync hooks' skip of CommonJS require() (registerHooks() sees require(), Module.register() never did) - the sync hooks' stripping of a __quibble query tag a coexisting --loader=quibble may have already added (finishResolve's normalizeUrl parameter) Adds test/esm-lib/quibble-loader-registration.test.js, which spawns fresh Node processes (so quibble has to auto-register) to check stubbing, CJS require() is untouched, no DEP0205 on stderr, and coexistence with another off-thread loader.
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.
module.register()is deprecated as of Node 26 and warns once per process that replaces an ES module without --loader. Usemodule.registerHooks()(synchronous, in-thread) instead when it's safe to:registerHooks()also intercepts CommonJSrequire(), whichregister()never did, so the sync resolve hook skips resolutions whosecontext.conditionsincludes "require".registerHooks()exists on Node 22.15+/23.5+, but a Node bug (fixed in 22.23, 24.12, 25.2 and 26.0) means a sync hook can't be combined with an off-thread loader (--loader, tsx, ts-node, ...) once ESM imports CommonJS. SoregisterHooks()is only used whereregister()doesn't exist at all, or on Node 26+.canRegisterLoader()now returns true if either API exists.Extracted the plan/resolve/load decision logic shared by the existing async hooks (
quibble.mjs) and the new sync hooks (quibble-sync-hooks.js) into its own module.What's left un-shared, because it's genuinely specific to one style of hook:
require()(registerHooks()seesrequire(),Module.register()never did)__quibblequery tag a coexisting--loader=quibblemay have already added (finishResolve'snormalizeUrlparameter)Adds
test/esm-lib/quibble-loader-registration.test.js, which spawns fresh Node processes (so quibble has to auto-register) to check stubbing, CJSrequire()is untouched, no DEP0205 on stderr, and coexistence with another off-thread loader.