fix(sentry): pass registerEsmLoaderHooks: false to skip Node 23+ DEP0205 (counter-PR to #800)#802
Merged
Merged
Conversation
Root-cause fix for the `[DEP0205] DeprecationWarning: module.register() is deprecated` warning that surfaces on Node.js >= 23 when running `npx @amplitude/wizard mcp serve`. The warning originates from `@sentry/node-core`'s `initializeEsmLoader` (via the transitive `import-in-the-middle`), which calls the deprecated `module.register()` for ESM-loader-based auto-instrumentation. Sentry exposes an official, documented option — `registerEsmLoaderHooks` — that skips that call entirely. Passing `false` is preferred over PR #800's `process.emitWarning` monkey-patch because: - Root cause, not symptom: Sentry never calls the deprecated API, so there is no warning to suppress. Nothing in the global warning channel is patched, so unrelated DEP0205 warnings (or future legitimate ones from other dependencies) still surface to users and CI. - Smaller, scoped surface: 1 option in `Sentry.init()` instead of patching `process.emitWarning` at the very top of `bin.ts`. - Forward-compatible: still honored by latest `@sentry/node-core` (10.53.1) and not tied to the exact wording of Node's warning string, so it survives Sentry rewording or Node tightening deprecation messages on 24/25/26+. The ESM loader hooks only power auto-instrumentation of *ESM-loaded* third-party libraries (DB drivers, frameworks loaded as ESM). The wizard's HTTP/`fetch` tracing patches Node's built-in modules directly, MCP servers are wrapped explicitly via `wrapMcpServerWithSentry`, and all error capture, breadcrumbs, logs, and spans work without ESM loader hooks — so disabling them has no functional cost. Verified: - `pnpm lint` clean - `pnpm test` (4471 / 4471 passing) - `mcp serve` cold start emits no DEP0205 on Node 20 / 22 / 24 / 26 - Regression test asserts `registerEsmLoaderHooks: false` is passed - Companion test asserts `process.emitWarning` is NOT patched — unrelated DEP0205 warnings still reach `process.on('warning')`
6833669 to
db78c44
Compare
5 tasks
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.
Summary
Root-cause alternative to PR #800. Instead of monkey-patching
process.emitWarninginbin.ts, pass Sentry's documentedregisterEsmLoaderHooks: falseoption toSentry.init()so@sentry/node-corenever calls the deprecatedmodule.register()in the first place.The DEP0205 warning surfaces on Node.js >= 23 when running
npx @amplitude/wizard mcp serve. It originates from@sentry/node-core->import-in-the-middleESM loader-hook setup, called frominitSentry(). The exact stack:Sentry exposes a public, documented option to skip that call:
registerEsmLoaderHooks. Verified against@sentry/node-core@10.47.0(src/sdk/index.ts:if (options.registerEsmLoaderHooks !== false) { initializeEsmLoader() }) and still honored in the latest10.53.1— so this approach is forward-compatible.Why this is better than PR #800
emitWarningpatch)registerEsmLoaderHooks: false)process.emitWarning)Sentry.init()process.on('warning')and stderrbin.ts(24 lines, must run before any import)src/lib/observability/sentry.ts(20 lines, insideinitSentry)The wizard does NOT use any of the features that
registerEsmLoaderHooksenables:fetchtracing patches Node's built-inhttp/https/undicimodules directly — no ESM hook neededwrapMcpServerWithSentrySo disabling them has zero functional cost.
Test plan
pnpm lintclean (prettier + eslint)pnpm test— 4471 / 4471 passingmcp servecold start emits no DEP0205 on Node 20.20.2, 22.14.0, 24.14.1, 26.0.0process.on('warning')listeners — covered by new regression testwizard-abort.tsuntouchedNew tests (
src/lib/observability/__tests__/sentry.test.ts)passes registerEsmLoaderHooks: false to Sentry.init— pins the option so a future refactor can't silently remove itdoes not patch process.emitWarning — other DEP0205 warnings still surface— fires a synthetic DEP0205 viaprocess.emitWarning, asserts it reachesprocess.on('warning')listenersRecommended next step
Close #800 in favor of this PR.
Checklist
gh pr createafter pushpnpm lintandpnpm testpassflows.ts/ navigationstore.tschanges: N/A — observability change only/reflectchecklist in this PR description or linked it — N/A, single-file root-cause fixNote
Medium Risk
Changes Sentry initialization behavior by disabling ESM loader hook registration, which could reduce auto-instrumentation for ESM-loaded libraries if any are used at runtime. Otherwise it’s a targeted observability change with regression tests covering the new option and ensuring Node warnings still propagate.
Overview
Prevents Node.js 23+
DEP0205deprecation warnings by passingregisterEsmLoaderHooks: falseintoSentry.init()insrc/lib/observability/sentry.ts, avoiding Sentry’s deprecatedmodule.register()-based ESM loader setup.Adds regression tests in
src/lib/observability/__tests__/sentry.test.tsto pin the new init option and to verify the PR does not globally suppress warnings (a synthetic DEP0205 still reachesprocess.on('warning')).Reviewed by Cursor Bugbot for commit db78c44. Bugbot is set up for automated code reviews on this repo. Configure here.