GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [SvelteKit 3] Sentry 11.8 build-time instrumentation breaks PostgreSQL bundling in Azure Functions · Issue #25470 · getsentry/sentry-javascript

[SvelteKit 3] Sentry 11.8 build-time instrumentation breaks PostgreSQL bundling in Azure Functions #25470

New issue
Copy link
New issue
Copy link
Closed
#25523
Closed
[SvelteKit 3] Sentry 11.8 build-time instrumentation breaks PostgreSQL bundling in Azure Functions#25470
#25523
Copy link
Assignees
s1gr1d
Labels
BugSvelteKit

Description

@ktarmyshov
ktarmyshov
opened on Oct 16, 2026
Issue body actions

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/sveltekit

SDK Version

11.8.0

Framework Version

"@sveltejs/kit": "^3.1.0",

Link to Sentry event

https://konstantin-tarmyshov.sentry.io/share/issue/9da37aba11594d27b8c7dcdfc60a1f5e/

Reproduction Example/SDK Setup

[SvelteKit 3] Sentry 11.8 build-time instrumentation breaks PostgreSQL bundling in Azure Functions

Environment

  • Sentry SDK: @sentry/[email protected]
  • SvelteKit: 3.1.0
  • Vite: 8.3.4
  • Rolldown: 1.2.14
  • PostgreSQL driver: [email protected]
  • Deployment: Azure Static Web Apps / Azure Functions, Node.js 22
  • Adapter: @ktarmyshov/svelte-adapter-azure-swa

The adapter uses a two-stage build: SvelteKit/Vite produces the first SSR bundle, then the adapter runs a separate Rolldown pass to generate the deployable Azure Functions output.

Problem

With Sentry enabled, a simple SvelteKit endpoint importing Client from pg fails in Azure:

Error: Cannot find module 'pg-types'
Require stack:
- /home/site/wwwroot/sk_render/_server.ts-<hash>.js

Public Sentry event:

https://konstantin-tarmyshov.sentry.io/share/issue/9da37aba11594d27b8c7dcdfc60a1f5e/

The endpoint does not connect to a database:

import { Client } from 'pg';

export function GET() {
  return new Response(typeof Client);
}

The failure disappears when either:

  1. pg is explicitly externalized during the initial Vite SSR build.
  2. Sentry is completely removed, without any explicit externalization.

Both alternatives have been verified on real Azure deployments, not just local builds.

Three verified Azure experiments

A. Sentry enabled, default SSR configuration — FAIL

Commit:
kt-npm-modules/svelte-adapter-azure-swa@473db3c

Failing Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38960205600/job/117173179946

Result: 39 passed, 1 failed.

The PostgreSQL smoke endpoint returns HTTP 500 instead of 200.

The first Vite SSR stage produces an approximately 801 KB PostgreSQL endpoint bundle containing unresolved CommonJS calls:

__require("pg-types")
__require("pg-protocol")
__require("pgpass")
__require("pg-cloudflare")
__require("pg-connection-string")

These calls survive the adapter's second Rolldown bundling pass and fail during Azure Functions execution.

B. Sentry enabled, ssr.external: ['pg'] — PASS

Commit:
kt-npm-modules/svelte-adapter-azure-swa@7a1f50f

Successful Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38961408425/job/117177863220

Result: 40 passed, including PostgreSQL and both Sentry error-ingestion tests.

Exact comparison of the failing and passing commits:

kt-npm-modules/svelte-adapter-azure-swa@473db3c...7a1f50f

The only functionally relevant change is:

ssr: {
  external: ['pg']
}

The first Vite SSR bundle now retains an ordinary import:

import { Client } from "pg";

The second Rolldown pass successfully bundles PostgreSQL and its dependencies.

However, Sentry explicitly warns:

[Sentry] The following packages are marked as external
in your bundler configuration but need to be bundled
for Sentry instrumentation to work: pg.

Remove them from your bundler's "external" configuration,
or use the Sentry Node SDK's runtime instrumentation instead.

Therefore, the workaround fixes deployment but may prevent automatic PostgreSQL instrumentation.

Passing the Sentry error-ingestion tests does not prove that PostgreSQL performance tracing remains functional.

C. Sentry removed, no ssr.external workaround — PASS

Diagnostic draft PR:
kt-npm-modules/svelte-adapter-azure-swa#335

Successful Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38966384532/job/117194085562

Result: 38 passed, including PostgreSQL.

This experiment completely removes Sentry SDK dependencies, its Vite plugin, hooks, server instrumentation, tracing configuration, and Sentry-specific tests.

The adapter and PostgreSQL smoke endpoint remain unchanged. No ssr.external: ['pg'] workaround is present.

The first Vite SSR PostgreSQL endpoint is now approximately 0.20 KB, and the generated Azure Function works correctly.

This is a broader Sentry-removal experiment, not a Vite-plugin-only isolation. It establishes that the failure disappears without Sentry, but does not identify the exact responsible hook.

Suspected cause

Investigation of the resolved Vite configuration with Sentry enabled showed that pg, pg-pool, and numerous other instrumented packages were present in:

  • ssr.noExternal
  • environments.ssr.resolve.noExternal

This appears to force PostgreSQL into the initial SSR bundle, producing partially bundled CommonJS code with unresolved runtime __require() calls.

Build-time resolver diagnostics confirmed that the PostgreSQL dependencies could be resolved. The unresolved calls are introduced into the generated output.

Without Sentry, Vite leaves PostgreSQL external in the first stage, allowing the downstream bundler to process its original dependency graph.

We suspect Sentry's build-time instrumentation / Orchestrion integration is responsible for this change in externalization behavior. However, the precise plugin hook has not yet been isolated.

Related issues

This appears similar to existing problems with build-time instrumentation in other Sentry framework integrations:

  • @sentry/nuxt 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle #24775 — @sentry/nuxt 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle. Fixed for Nuxt in Sentry 11.2.0.
  • @sentry/react-router 11: build-time instrumentation inlines CommonJS that default-imports @sentry/core; server crashes at startup #25339 — @sentry/react-router 11: build-time instrumentation inlines CommonJS, causing server startup failures. Currently open.

Related Rolldown investigations: [#10643](rolldown/rolldown#10643) and [#9407](rolldown/rolldown#9407).

Expected behavior

Sentry's build-time instrumentation should not cause an otherwise working PostgreSQL dependency to become partially bundled and fail after downstream server bundling.

Ideally, PostgreSQL instrumentation should remain functional without requiring ssr.external: ['pg'].

Questions

  1. Does the SvelteKit Sentry integration intentionally force pg into ssr.noExternal through build-time instrumentation?
  2. Is this the same class of problem addressed for Nuxt in @sentry/nuxt 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle #24775, and could the SvelteKit integration require a similar fix?
  3. Is there a supported way to retain PostgreSQL instrumentation in a two-stage SvelteKit/Azure Functions build without forcing pg to be external?

All three configurations have publicly accessible commits and successful or failing real Azure E2E jobs.

The diagnostic no-Sentry PR is intentionally marked do not merge. We want to retain Sentry and its database instrumentation in the actual application.

Steps to Reproduce

Three verified Azure experiments

A. Sentry enabled, default SSR configuration — FAIL

Commit:
kt-npm-modules/svelte-adapter-azure-swa@473db3c

Failing Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38960205600/job/117173179946

Result: 39 passed, 1 failed.

The PostgreSQL smoke endpoint returns HTTP 500 instead of 200.

The first Vite SSR stage produces an approximately 801 KB PostgreSQL endpoint bundle containing unresolved CommonJS calls:

__require("pg-types")
__require("pg-protocol")
__require("pgpass")
__require("pg-cloudflare")
__require("pg-connection-string")

These calls survive the adapter's second Rolldown bundling pass and fail during Azure Functions execution.

B. Sentry enabled, ssr.external: ['pg'] — PASS

Commit:
kt-npm-modules/svelte-adapter-azure-swa@7a1f50f

Successful Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38961408425/job/117177863220

Result: 40 passed, including PostgreSQL and both Sentry error-ingestion tests.

Exact comparison of the failing and passing commits:

kt-npm-modules/svelte-adapter-azure-swa@473db3c...7a1f50f

The only functionally relevant change is:

ssr: {
external: ['pg']
}

The first Vite SSR bundle now retains an ordinary import:

import { Client } from "pg";

The second Rolldown pass successfully bundles PostgreSQL and its dependencies.

However, Sentry explicitly warns:

[Sentry] The following packages are marked as external
in your bundler configuration but need to be bundled
for Sentry instrumentation to work: pg.

Remove them from your bundler's "external" configuration,
or use the Sentry Node SDK's runtime instrumentation instead.

Therefore, the workaround fixes deployment but may prevent automatic PostgreSQL instrumentation.

Passing the Sentry error-ingestion tests does not prove that PostgreSQL performance tracing remains functional.

C. Sentry removed, no ssr.external workaround — PASS

Diagnostic draft PR:
kt-npm-modules/svelte-adapter-azure-swa#335

Successful Azure job:
https://github.com/kt-npm-modules/svelte-adapter-azure-swa/actions/runs/38966384532/job/117194085562

Result: 38 passed, including PostgreSQL.

This experiment completely removes Sentry SDK dependencies, its Vite plugin, hooks, server instrumentation, tracing configuration, and Sentry-specific tests.

The adapter and PostgreSQL smoke endpoint remain unchanged. No ssr.external: ['pg'] workaround is present.

The first Vite SSR PostgreSQL endpoint is now approximately 0.20 KB, and the generated Azure Function works correctly.

This is a broader Sentry-removal experiment, not a Vite-plugin-only isolation. It establishes that the failure disappears without Sentry, but does not identify the exact responsible hook.

Expected Result

Default SvelteKit App config, default Sentry config -> pg* are bundled -> deployment to SWA works

Actual Result

Default SvelteKit App config, default Sentry config -> pg* are NOT bundled -> deployment to SWA FAILS

Additional Context

No response

Priority

No response

Activity

  1. ktarmyshov
    added
    Bug
    on Oct 16, 2026
  2. getsantry
    added
    Waiting for: Product Owner
    on Oct 16, 2026
  3. linear-code commented on Oct 16, 2026

    @linear-code
    linear-codeBot
    on Oct 16, 2026 – with Linear Code
    More actions

    JS-3951

  4. getsantry
    added this to GitHub Issues with 👀 3on Oct 16, 2026
  5. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 16, 2026
  6. github-actions
    added
    SvelteKit
    on Oct 16, 2026
  7. s1gr1d
    self-assigned this
    on Oct 19, 2026
  8. s1gr1d commented on Oct 19, 2026

    @s1gr1d
    s1gr1d
    on Oct 19, 2026
    Member
    More actions

    Thanks for the detailed report!

    1. Yes, this is intentional. To instrument pg, Sentry changes its code during the build. The bundler can only change code that it bundles, so we add pg to ssr.noExternal.
    2. Yes, it's the same class of problem as @sentry/nuxt 11: CommonJS packages inlined for build-time instrumentation break in the Nitro bundle #24775. Only pg is bundled. Its dependencies (pg-types, pg-protocol, ...) stay external. Vite 8 (Rolldown) emits their require() calls as __require("pg-types"). That works when node_modules exists at runtime. But your adapter's second Rolldown pass can't follow these calls, so they stay unresolved.
    3. Not yet. Until then, keep ssr: { external: ['pg'] }. You won't get pg query spans, but all other packages stay instrumented. To turn off build-time instrumentation completely, set sentrySvelteKit({ buildTimeInstrumentation: false }).
  9. getsantry
    removed
    Waiting for: Product Owner
    on Oct 19, 2026
  10. getsantry
    moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 19, 2026
  11. s1gr1d
    added a commit that references this issue on Oct 19, 2026

    docs(sveltekit): Document the buildTimeInstrumentation option (#20078)

    f92f029
  12. s1gr1d commented on Oct 19, 2026

    @s1gr1d
    s1gr1d
    on Oct 19, 2026
    Member
    More actions

    Thanks! I could only reproduce this with a flat node_modules, which is what npm and Yarn classic create. Your demo app uses npm, so that fits.

    Just as a note: pnpm's default layout hides the bug. Vite can't resolve pg-types from the project root there, so it bundles it together with pg. With nodeLinker: hoisted, pnpm installs flat node_modules too, and the crash shows up.

    All requirements for this problem:

    • Vite 8 (docs)
    • An instrumented CJS package
    • A flat node_modules (npm or Yarn classic). With pnpm's isolated layout, Vite cannot resolve pg-types from the project root and bundles it anyway
    • A deployment without node_modules (like on azure)
    Reacted by Konstantin Tarmyshov
  13. JPeer264
    added a commit that references this issue on Oct 19, 2026

    fix(server-utils): Bundle the CommonJS dependencies of instrumented p…

    This issue will close once commit bfe4ef2 is merged into the 'develop' branch.
    bfe4ef2
  14. s1gr1d
    added a commit that references this issue on Oct 20, 2026

    fix(server-utils): Bundle the CommonJS dependencies of instrumented p…

    This issue will close once commit 617d0ef is merged into the 'develop' branch.
    617d0ef
  15. s1gr1d commented on Oct 20, 2026

    @s1gr1d
    s1gr1d
    on Oct 20, 2026
    Member
    More actions

    This is going to be fixed with this PR: #25523

    Reacted by Konstantin Tarmyshov
  16. ktarmyshov commented on Oct 20, 2026

    @ktarmyshov
    ktarmyshov
    on Oct 20, 2026
    Author
    More actions

    @s1gr1d

    Thank you for fast fix!

  17. getsantry
    added
    Waiting for: Product Owner
    on Oct 20, 2026
  18. getsantry
    moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 20, 2026
  19. s1gr1d
    added a commit that references this issue on Oct 20, 2026

    fix(server-utils): Bundle the CommonJS dependencies of instrumented p…

    This issue will close once commit e2fe6d3 is merged into the 'develop' branch.
    e2fe6d3
  20. s1gr1d
    closed this as completedin #25523on Oct 20, 2026
  21. s1gr1d
    added a commit that references this issue on Oct 20, 2026

    fix(server-utils): Bundle the CommonJS dependencies of instrumented p…

    This issue will close once commit ebe8fdc is merged into the 'develop' branch.
    ebe8fdc
  22. getsantry
    removed
    Waiting for: Product Owner
    on Oct 20, 2026
  23. github-actions commented on Oct 23, 2026

    @github-actions
    github-actionsBot
    on Oct 23, 2026 – with GitHub Actions
    Contributor
    More actions

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #25523, which was included in the 11.9.0 release.

    Reacted by Konstantin Tarmyshov
    Reacted by Konstantin Tarmyshov
  24. isaacs
    added 3 commits that reference this issue on Oct 29, 2026

    test(bundler-tests): Guard server runtime entries against build-time …

    a837f5a

    test(bundler-tests): Guard server runtime entries against build-time …

    8cbb9ca

    test(bundler-tests): Guard server runtime entries against build-time …

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

Metadata

Metadata

Assignees

  • @s1gr1d
    s1gr1d

Labels

BugSvelteKit

Projects

  • GitHub Issues with 👀 3
    Status
    Waiting for: Product Owner
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.