Skip to content

meriyah.mjs missing at runtime in Next.js "standalone" builds since 10.59.0 (server-utils → meriyah not fully traced by nft) #23034

Description

@lourd

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

10.69.0

Framework Version

Next.js 16.3.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Next.js app with output: "standalone" and withSentryConfig.
  2. Initialize the server SDK from instrumentation.ts.
  3. next build, then run the standalone server (node .next/standalone/server.js, or deploy the standalone output).
  4. Observe the runtime failure resolving meriyah/dist/meriyah.mjs; confirm meriyah.cjs is present in the traced output but meriyah.mjs is not.

Expected Result

The standalone build includes every file @sentry/server-utils needs at runtime, including meriyah/dist/meriyah.mjs.

Actual Result

Only meriyah/dist/meriyah.cjs is traced into the standalone output; the ESM entry loaded at runtime needs meriyah.mjsERR_MODULE_NOT_FOUND.

Additional Context

After bumping @sentry/nextjs/@sentry/node from 10.37.0 to 10.69.0, the standalone server build fails at runtime with a missing-module error for:

.../node_modules/.pnpm/meriyah@6.1.4/node_modules/meriyah/dist/meriyah.mjs

The standalone output contains meriyah/dist/meriyah.cjs but not meriyah/dist/meriyah.mjs, so the ESM entry that gets loaded at runtime cannot resolve the parser.

Root cause analysis

meriyah entered the dependency graph at @sentry/node@10.59.0 (first version whose @sentry/server-utils@10.59.0 depends on @apm-js-collab/code-transformer@^0.15.0, which depends on meriyah@^6.1.4). As of server-utils@10.68.0+, meriyah is also a direct dependency of @sentry/server-utils.

@sentry/server-utils is dual-published, and its ESM build imports meriyah:

// @sentry/server-utils/build/esm/orchestrion/bundler/subscribeInjection.js
import { parse } from 'meriyah';

meriyah@6.1.4's package.json has an unusual exports map:

"main": "dist/meriyah.cjs",
"exports": {
  "types":       "./dist/types/meriyah.d.ts",
  "module-sync": "./dist/meriyah.mjs",   // ESM
  "require":     "./dist/meriyah.cjs",   // CJS
  "default":     "./dist/meriyah.mjs"    // ESM fallback
}

Note there is no plain import key (the ESM side lives under module-sync + default), and require is ordered before default.

Next.js output file tracing (@vercel/nft) resolves specifiers with a condition set that includes both import and require. Because exports matching is first-match-in-insertion-order and require appears before default, nft resolves meriyah to the requiredist/meriyah.cjs target and copies only that into the standalone bundle. Node's real ESM loader, resolving the same import, does not have the require condition active, so it falls through to module-sync/defaultdist/meriyah.mjs, which was never traced/copied.

Result: nft's traced file set and Node's runtime resolution diverge for this one dual package, so meriyah.mjs is absent from output: "standalone".

Workaround

Force-include the missing file via next.config:

outputFileTracingIncludes: {
  "/*": ["../node_modules/.pnpm/meriyah@*/node_modules/meriyah/dist/*.mjs"],
},

Fixes

  • Have withSentryConfig add the required @sentry/server-utils runtime files (notably meriyah's .mjs) to outputFileTracingIncludes automatically, the same way other packages that trip nft are handled.
  • Fix this upstream, in either @vercel/nft or meriyah

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

Status
Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions