feat: Convert code to CJS - #51
Closed
timfish wants to merge 2 commits into
Closed
Conversation
hook.mjs has no genuine ESM dependencies of its own; converting it to plain CJS lets consumers reach it via require() without triggering Node's require(esm) bridge.
Adds hook-sync.cjs alongside hook-sync.mjs and a conditional
"./hook-sync" export so require('@apm-js-collab/tracing-hooks/hook-sync')
resolves synchronously to real CJS, without pulling consumers through
Node's require(esm) bridge. hook.mjs and hook-sync.mjs now delegate to
hook-core.js; their public APIs are unchanged.
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.
hook-sync.mjsis the only synchronous entry point to this package, but it's ESM-only. Consumers that ship CJS builds have no choice but torequire('@apm-js-collab/tracing-hooks/hook-sync.mjs')- i.e.require(esm).The
Module.register()loader thread on Node 22.15–24.12 spawns a loader thread that re-runs--requirepreloads. If the preloads require graph reaches therequire(esm)ofhook-sync.mjson that thread, Node throws:The resolveSync() method is not implementedbecause the loader thread's async-customized loader has no synchronous resolve chain. The thread finishes half-initialized, and any resolve request that reaches it afterwards crashes the host process:
A (much more) viable alternative is that we instruct users not to use
--require, specifically because it results in all that code being run on the loader thread too! This does not impact--import.