feat: add source map support for production error stack traces#306
Merged
feat: add source map support for production error stack traces#306
Conversation
- Add source-map-support package for automatic stack trace rewriting - Emit build-manifest.mjs during build with sourcemap configuration - Support all Vite sourcemap modes: true, inline, hidden, server, server-inline - Server-only modes (server, server-inline) skip client bundle source maps - Install source-map-support at production startup with mode-specific config - Skip source-map-support on edge runtimes and when native --enable-source-maps is set - Add SOURCEMAP_SUPPORT runtime symbol and virtual module resolution - Add adapter support: Vercel (NODE_OPTIONS), Cloudflare (upload_source_maps), Netlify (.map deploy) - Include .map files in adapter server bundles when sourcemap is enabled - Support sourcemap option in react-server.config.mjs - Add production error logging with logger in RSC onError handlers - Add comprehensive tests for sourcemap build output - Update CLI docs (EN + JA) with per-option headings and table of contents entries
|
✅ Documentation preview deployed to: https://react-server-docs-ixpovnu4a-lazarv-team.vercel.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds source map support for production error stack traces, enabling developers to see original source file locations in server-side errors instead of bundled code references.
Closes #284
Features
Source map modes
All Vite sourcemap modes are supported via
--sourcemap:true.mapfiles.mapfilesinlinehidden.mapfiles (no URL comment).mapfiles (no URL comment)sourceMappingURLserver.mapfilesserver-inlineRuntime stack trace rewriting
source-map-supportpackage to automatically rewrite production error stack tracesNODE_OPTIONS='--enable-source-maps'is already set to avoid conflictshookRequirefor inline, customretrieveSourceMapfor hiddenConfiguration
Via CLI:
Via config file (
react-server.config.mjs):Adapter support
NODE_OPTIONS: "--enable-source-maps"to.vc-config.jsonenvironmentupload_source_maps: truein generatedwrangler.toml.mapfiles alongside edge/serverless functionsserver/**/*.mapin server file globsImplementation details
Build-time
build-manifest.mjsas an ES module (export default { sourcemap: ... }) for edge compatibility.react-server/server/build-manifestin all 3 resolution paths (RSC loader, SSR loader, edge bundler)falseto client buildsRuntime
manifest.mjsloads the build manifest and sets theSOURCEMAP_SUPPORTruntime symbolssr-handler.mjsreads the symbol and installssource-map-supportwith appropriate optionsonErrorhandlers log errors withlogger?.error(e)in production for visibilityFiles changed
Core
packages/react-server/server/symbols.mjs— NewSOURCEMAP_SUPPORTsymbolpackages/react-server/lib/build/action.mjs— Build manifest emission, config file supportpackages/react-server/lib/build/server.mjs— Server sourcemap normalizationpackages/react-server/lib/build/client.mjs— Client sourcemap suppression for server-only modespackages/react-server/lib/build/edge.mjs— Edge sourcemap normalizationpackages/react-server/lib/start/manifest.mjs— Build manifest loadingpackages/react-server/lib/start/ssr-handler.mjs— Source map support installationpackages/react-server/lib/loader/node-loader.mjs— Virtual module resolutionpackages/react-server/lib/loader/node-loader.react-server.mjs— Virtual module resolutionpackages/react-server/server/render-rsc.jsx— Production error loggingpackages/react-server/bin/commands/build.mjs— CLI help textpackages/react-server/package.json—source-map-supportdependencyAdapters
packages/react-server/adapters/core.mjs— Conditional.mapfile inclusionpackages/react-server/adapters/vercel/index.mjs—NODE_OPTIONSin.vc-config.jsonpackages/react-server/adapters/cloudflare/index.mjs—upload_source_mapsin wrangler configpackages/react-server/adapters/netlify/index.mjs— Edge function.mapfile copyDocs
docs/src/pages/en/(pages)/framework/cli.mdx— Restructured with per-option headings + sourcemap docsdocs/src/pages/ja/(pages)/framework/cli.mdx— Same restructuring in JapaneseTests
test/__test__/sourcemap.spec.mjs— Build output tests (manifest content,.mapfile presence, server-inline mode)test/fixtures/sourcemap.jsx— Test fixture componentVS Code
.vscode/launch.json— Debug configuration for production + sourcemap.vscode/tasks.json— Build task with--sourcemap