Repository navigation
server-runtime-injection: build/esm/package.json is not traced, so hook.js fails to load as ESM on Vercel (Node 22) #25480
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
11.8.0 (latest): build/trace issue confirmed locally. Runtime warning reproduced on Vercel with 11.6.0; register.ts is identical between 11.6.0 and 11.8.0.
Framework Version
Next.js 16.3.8 on Vercel Functions nodejs22.x (webpack build, default next build)
Link to Sentry event
No response
Reproduction Example/SDK Setup
Related to #23831 (closed). After #23687, build/esm/hook.js is traced, but the sibling build/esm/package.json ({"type":"module"}) is not.
// instrumentation.ts
import * as Sentry from '@sentry/nextjs'
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, tracesSampleRate: 0.1 })
}
}
export const onRequestError = Sentry.captureRequestErrorSteps to Reproduce
- Deploy a Next.js 16 app using @sentry/nextjs (11.6.0–11.8.0) to Vercel on the nodejs22.x runtime.
- Trigger a cold start of any Node.js function (e.g. GET /api/health).
- Check the runtime logs.
Expected Result
The diagnostics-channel injection hook registers successfully (or is skipped silently when nothing needs it). No warnings.
Actual Result
Every cold start logs this pair:
[Sentry] Failed to register diagnostics-channel injection hooks, so channel-based integrations will not record spans. See https://docs.sentry.io/platforms/javascript/guides/node/troubleshooting/
(node:7) Warning: Failed to load the ES module: /var/task/node_modules/@sentry/server-runtime-injection/build/esm/hook.js. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.
Additional Context
Cause
- On Node < 24.13,
registerDiagnosticsChannelInjection()usesModule.register(join(__dirname, '../esm/hook.js')). - Since fix(server-runtime-injection): Resolve the orchestrion ESM hook by path so build tracers follow it #23687,
@vercel/nftfollows that literal path, sobuild/esm/hook.jsis traced. - What marks
build/esmas ESM isbuild/esm/package.json({"type":"module"}). Nothing references it, so it is not traced. The package rootpackage.jsonhas notypefield. - In the deployed bundle, the nearest
package.jsonforhook.jsis therefore the root one, so Node 22 treatshook.jsas CommonJS and fails on itsexportstatements.
Evidence
- Local
next build, scanning all 127.nft.jsonfiles:build/esm/hook.jsappears in 75,build/esm/package.jsonin 0, the package rootpackage.jsonin 75. Identical result on 11.6.0 and 11.8.0. - Same build on Vercel
nodejs22.x: a cold start with injection enabled produced the warning pair above. WithenableRuntimeChannelInjection: false, it produced none. A positive-control log line from the same deployment confirmed that logs were being collected. - Not reproducible locally on Node 24.20: that version uses
Module.registerHooks(), and even when forced throughModule.register(), syntax detection loads the untyped.jsfile as ESM. This is why it slips past local testing.
Impact
Users who depend on any of the instrumented libraries (pg, prisma, redis, …) silently lose those spans on Vercel Node 22. Error capture is not affected.
Possible fixes
- (a) Reference
build/esm/package.jsonin a way nft follows (e.g. arequire.resolve/readFileSyncof it next to the hook path). - (b) Ship the hook as
hook.mjs, so its format no longer depends on a package.json.
Workaround
outputFileTracingIncludes for node_modules/@sentry/server-runtime-injection/build/esm/package.json, or enableRuntimeChannelInjection: false if no instrumented libraries are used.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Oct 17, 2026
JS-3952
andreiborza commentedon Oct 19, 2026
Hi @starbear6308, thanks for filing this. We'll look into it.