Skip to content

@sentry/nextjs ≥ 11.13: bun --bun next dev fails at startup with "Cannot find module '@sentry/nextjs-<hash>'" (Turbopack, isolated install) #26911

Done

Description

@finsterwalder

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

11.18.0

Framework Version

NextJS 16.4.6

Link to Sentry event

No response

Reproduction Example/SDK Setup

export default withSentryConfig(withNextIntl(nextConfig), {
  org: process.env.SENTRY_ORG,
  project: process.env.SENTRY_PROJECT_FRONTEND,
  authToken: process.env.SENTRY_AUTH_TOKEN,
  // Upload a wider set of client files for readable stack traces.
  widenClientFileUpload: true,
  // Source maps are uploaded to Sentry, never publicly served.
  sourcemaps: { deleteSourcemapsAfterUpload: true },
  // Only print upload logs in CI.
  silent: !process.env.CI,
  webpack: {
    treeshake: { removeDebugLogging: true },
    reactComponentAnnotation: { enabled: true },
  },
  ...(process.env.SENTRY_RELEASE
    ? { release: { name: process.env.SENTRY_RELEASE } }
    : {}),
});

Steps to Reproduce

Starting the Next.js dev server under Bun fails right after Ready while loading the instrumentation hook. It worked on @sentry/nextjs 11.12.0 and broke in 11.13.0. It still fails in 11.18.0.

$ bun --bun next dev
▲ Next.js 16.4.6 (Turbopack)
✓ Ready in 196ms
Error: An error occurred while loading instrumentation hook: Failed to load external module
@sentry/nextjs-c6af2e4dbcd5c896: ResolveMessage: Cannot find module '@sentry/nextjs-c6af2e4dbcd5c896'
Require stack:

  • .next/dev/server/chunks/[root-of-the-server]__….js
    at module evaluation (src/instrumentation.ts:1:1299)

The hashed name is one of the aliases Turbopack creates as symlinks under .next/dev/node_modules/ for
externalized packages. If @sentry/nextjs isn't the first external to load, the same error names
another one: pino-, or @sentry/server-runtime-injection-/register. So this isn't specific
to one package.

Environment

  • @sentry/nextjs: 11.12.0 works; 11.13.0 and 11.18.0 fail
  • Next.js 16.4.6 with Turbopack (next dev default)
  • Bun 1.4.5, macOS arm64, bun --bun next dev
  • Bun's isolated linker in a monorepo (so Turbopack uses hashed external aliases)
  • withSentryConfig(...) in next.config.ts, src/instrumentation.ts with a static import * as Sentry
    from '@sentry/nextjs'

Steps to reproduce

  1. Use a Next.js 16.2+ app (Turbopack) with @sentry/nextjs ≥ 11.13 installed via Bun's isolated
    linker.
  2. Wrap the config: export default withSentryConfig(nextConfig, { silent: true }).
  3. Add src/instrumentation.ts that imports @sentry/nextjs.
  4. rm -rf .next && bun --bun next dev

I haven't built a standalone minimal repository yet, so the steps above are generic. I bisected inside
a larger monorepo.

What I verified

  • Version bisect, clean .next each time: 11.12.0 starts; 11.13.0 fails (two runs); 11.18.0 fails.
  • Runtime: next dev under Node starts fine on 11.18.0, so only the Bun runtime is affected.
  • The wrapper call matters:
    • Removing withSentryConfig makes Bun dev work.
    • Only importing @sentry/nextjs/config, without calling it, also works.
    • A minimal call, withSentryConfig(config, { silent: true }), fails.
  • Ruled out:
    • The new bun/deno export conditions (I removed them from the installed package.json).
    • The serverExternalPackages list (even [] still fails).
    • The returned env, experimental.clientTraceMetadata and webpack fields.
  • Not related to missing files: after the failure, require() of the hashed alias from the chunk
    directory works. The failure depends on startup timing or state.

Likely cause

maybeSetTurbopackPluginRuntimeStrategyOption in withSentryConfig: on Bun with Next ≥ 16.2 it sets
experimental.turbopackPluginRuntimeStrategy = "workerThreads". The code comment says this avoids
childProcesses failing or hanging on Bun builds, because execArgv contains --bun. It doesn't apply
under Node, which matches why Node works.

Overriding it to childProcesses for dev makes bun --bun next dev work. I tested three clean runs, and
/de/login returned 200. The exact mechanism isn't confirmed. workerThreads plausibly changes when or where Turbopack creates the .next/dev/node_modules/*- symlinks relative to Bun's module resolution. Either way, Bun then can't resolve those hashed externals at startup.

Workaround

Dev only, in next.config.ts:

const nextConfig: NextConfig = {
...(process.env.NODE_ENV === 'development'
? { experimental: { turbopackPluginRuntimeStrategy: 'childProcesses' as const } }
: {}),
// ...
};

next build keeps Sentry's workerThreads default. A production build under Bun passes with this workaround.

Expected behavior

bun --bun next dev starts without errors, as on 11.12.0, without needing to override Sentry's strategy default.

Additional note (separate, production)

With Bun as the production runtime, @sentry/nextjs resolves its bun export condition (build/cjs/index.bun.js), which requires the optional peer @sentry/bun. Next's standalone file tracing follows the node condition and omits both. bun server.js then fails with the same misleading "Cannot find module '@sentry/nextjs-'" message. I fixed it by adding @sentry/bun as a dependency and listing node_modules/@sentry/bun//* and node_modules/@sentry/nextjs/build//* in outputFileTracingIncludes. A note in the docs would help.

This analysis was done with the help of Claude.

Expected Result

The Next server starts fine in dev mode.

Actual Result

The Next server does not start in dev mode

Additional Context

No response

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.

Activity

  1. linear-code commented on Nov 26, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 26, 2026
  3. self-assigned this
    on Nov 26, 2026
  4. JPeer264 commented on Nov 26, 2026

    @JPeer264
    Member

    Thanks for bringing this up. Does it work if you run the following: bun add @sentry/bun ?

    I think I've added some breaking change by accident if that is the case. In the meantime I'll try to dig a little into it if something else could be the issue

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 26, 2026
  6. finsterwalder commented on Nov 26, 2026

    @finsterwalder
    Author

    Yes, I have @sentry/bun 11.18.0 as an explicit dependency. That does not solve the issue.

  7. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 26, 2026
  8. JPeer264 commented on Nov 26, 2026

    @JPeer264
    Member

    Ok thanks for confirming, I think I already found the issue. A fix is on its way.

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 26, 2026
  10. github-actions commented on Nov 26, 2026

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #26923, which was included in the 11.19.0 release.

  11. JPeer264 commented on Nov 26, 2026

    @JPeer264
    Member

    @finsterwalder so as mentioned above this has been released in v11.19.0. If you have any other issues just let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions