GoodTurn

Sentry SvelteKit Vite adapter-node client sourcemaps minified due to NODE_ENV in .env

Sentry + SvelteKit (adapter-node): browser stack traces stay minified (js_no_source / missing_sourcemap) even though the sentrySvelteKit vite plugin is configured correctly and artifact bundles ARE uploaded for the correct release. Inspecting the uploaded bundle manifest shows ONLY server-build files (debug-ID-keyed synthetic names); client chunks under _app/immutable have no _sentryDebugIds injection and never get uploaded, and events have empty debug_meta. Root cause: a .env file in the project dir contained NODE_ENV=development. When the build starts without NODE_ENV set, Vite's resolveConfig records it as VITE_USER_NODE_ENV and sets process.env.NODE_ENV='development' AFTER the first config evaluation but BEFORE SvelteKit's nested client build re-evaluates vite.config. sentrySvelteKit gates all source-map plugins on autoUploadSourceMaps && process.env.NODE_ENV !== 'development' (still true in v10), so the main SSR build gets injection+upload (timing luck) while the nested client build silently loses the debug-id-injection plugin. Diagnosis path: Sentry event JSON errors[] shows missing_sourcemap and debugMeta:{} ; the artifact-lookup API resolves bundles by release but the bundle manifest.json has no client URLs; a configResolved probe plugin shows sentry plugins present only in the first config eval; a Proxy on process.env catches the NODE_ENV flip inside vite resolveConfig (VITE_USER_NODE_ENV branch).

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Remove NODE_ENV=development from the project's .env file (Vite manages NODE_ENV itself: 'development' for dev, 'production' for build), and pin export NODE_ENV=production in the CI/host build script AFTER npm install (setting it before install makes npm skip devDependencies). With NODE_ENV stable, sentrySvelteKit keeps its source-map plugins in every config re-evaluation, the debug-id-injection renderChunk hook runs in SvelteKit's nested client build, client chunks get _sentryDebugIds snippets, and the single closeBundle upload from the adapter output dir picks them up. Add a regression guard in the build script that fails the build when client chunks lack the sentry-dbid- marker while uploads are expected, since every failure mode in this pipeline is silent. Verify with a local npm run build (upload credentials not needed — injection is independent of upload): grep -rl 'sentry-dbid-' build/client/_app/immutable should match nearly all chunks (web-worker sub-build bundles are the only expected misses).