Source Maps and Stack Traces: Upload, Custom Builds, and Limits
How Cloudflare Workers and Pages upload source maps, remap stack traces in logs, and configure Wrangler, Vite, and custom builds.
This page summarises Cloudflare documentation on source maps for Workers and Pages Functions: why production stack traces look wrong without them, how Wrangler and cf upload maps by default, what upload_source_maps controls, and what framework or custom builds must do themselves.
Source maps and stack traces: why logs show minified code
Section titled “Source maps and stack traces: why logs show minified code”Stack traces help when an unhandled exception occurs: they show which functions ran, in what order, from which line and file, and with what arguments. Most JavaScript is bundled, often transpiled, and minified before deploy, which shrinks bundles and can turn TypeScript into JavaScript.
Source maps translate compiled and minified code back to the original code that you wrote. Source maps are combined with the stack trace returned by the JavaScript runtime to present you with a stack trace.
— Cloudflare, Source maps and stack traces (Workers)
Without uploaded maps, traces typically point at a single minified file with wrong line numbers and .js instead of .ts. With maps, methods reference the correct files and lines. The same idea applies to Pages Functions.
Bundlers and preprocessors that commonly emit source maps include Webpack, Vite, esbuild, and Parcel, plus transpilers such as Babel and TypeScript, as described in Chrome DevTools: source maps.
upload_source_maps: default upload, strict mode, and opt-out
Section titled “upload_source_maps: default upload, strict mode, and opt-out”From Wrangler 4.150.0, wrangler deploy, wrangler versions upload, and wrangler preview generate and upload source maps by default. You no longer need upload_source_maps just to get original file names and line numbers in traces.
From Wrangler 4.150.0, wrangler deploy, wrangler versions upload, and wrangler preview generate and upload source maps by default. You no longer need to set upload_source_maps to get stack traces with your original file names and line numbers.
— Cloudflare, Wrangler and cf now upload source maps by default
The upload_source_maps field in Wrangler configuration is optional and controls generation and upload on those commands:
| Setting | Behavior |
|---|---|
| Unset (default on Wrangler ≥ 4.150.0) | Upload source maps; skip any that cannot be resolved |
true |
Upload maps; fail the deploy if a map cannot be resolved |
false |
Do not upload source maps |
On Wrangler versions before 4.150.0, maps upload only when upload_source_maps is set to true, as noted in Enable source maps.
How to turn off source map upload with Wrangler
Section titled “How to turn off source map upload with Wrangler”Set upload_source_maps to false in Wrangler configuration, or pass --no-upload-source-maps to wrangler deploy or wrangler versions upload. See Disable source maps.
{ "upload_source_maps": false}Where remapped stack traces appear (and what they do not change)
Section titled “Where remapped stack traces appear (and what they do not change)”After a Worker or Pages Function throws, Cloudflare fetches the source map and remaps the exception stack to your original source. Remapped traces show in Workers Logs, real-time logs, Tail Workers, and Workers Issues. Errors and exceptions and Profiling in production also assume maps are enabled for readable frames.
Source maps are applied after your Worker runs, so they don’t affect CPU time, bundle size, or cold starts.
— Cloudflare, Wrangler and cf now upload source maps by default
Remapping is asynchronous and out of band: it does not affect the Worker’s CPU use at request time. Source maps are not available inside the runtime—console.log() on a stack’s stack property still shows the deployed bundle, not deobfuscated source (Stack traces (Workers), Stack traces (Pages)). Cloudflare remaps line by line and leaves any line it cannot map unchanged.
Framework and custom builds: generate maps before Wrangler uploads
Section titled “Framework and custom builds: generate maps before Wrangler uploads”Wrangler and cf deploy upload maps that already exist in the build output; they do not replace your bundler. Framework and custom builds must generate maps.
When Vite or another build tool bundles your Worker, that tool must generate source maps. Wrangler only uploads maps that already exist in the build output.
— Cloudflare, Frameworks and custom builds
For other tools, emit external .map files and keep sourceMappingURL references in generated JavaScript. Do not put server-side maps in public asset directories (Workers best practices).
cf deploy, Cloudflare Vite plugin, and build.sourcemap
Section titled “cf deploy, Cloudflare Vite plugin, and build.sourcemap”cf deploy uploads every source map in the build output by default. With the Cloudflare Vite plugin 1.64.0 or later, Worker builds generate source maps by default (changelog). To opt out, set build.sourcemap to false for the Worker’s Vite environment (Disable source maps, Migrate a Wrangler project).
If build.sourcemap is enabled for a Worker environment in Vite, upload_source_maps: true is added to the generated Wrangler config when using migrating from wrangler dev—but upload_source_maps alone does not generate maps in a Vite build.
Example pattern from the React + Vite guide:
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({ plugins: [react(), cloudflare({ viteEnvironment: { name: "worker" } })], environments: { worker: { build: { sourcemap: true } }, },});The Worker environment generates maps; the client environment keeps its own build.sourcemap settings.
Custom build.command and webpack (Wrangler v1 type = webpack)
Section titled “Custom build.command and webpack (Wrangler v1 type = webpack)”If you use a custom build, Wrangler uploads external maps it finds and skips unresolvable maps (for example inline data: source maps) unless upload_source_maps is true, which fails the upload instead (changelog).
Wrangler v2 removed type = webpack and webpack_config. Projects that still need webpack beyond simple loaders can use Migrate webpack projects: add wranglerjs-compat-webpack-plugin, run webpack via a build script, remove type and webpack_config, and point Wrangler at the output:
{ "main": "./worker/script.js", "build": { "command": "webpack --config webpack.config.js" }}Your webpack pipeline must still emit source maps if you want remapped production traces.
Pages Functions: enable upload and avoid public client maps
Section titled “Pages Functions: enable upload and avoid public client maps”For Pages, support for uploading source maps is described as open beta with minimum Wrangler 3.60.0 (Source maps and stack traces (Pages)). Enable with --upload-source-maps on wrangler pages deploy or upload_source_maps: true in the Pages Wrangler configuration when using the Pages build environment.
When debugging full-stack apps, many tools generate maps for client and server. Debugging and logging (Pages Functions) warns that public client source maps can expose application source—configure the build to emit only server maps or strip client maps before deploy.
Source map size limits and GA status
Section titled “Source map size limits and GA status”Source maps are generally available for Workers. Maximum upload size is 15 MiB gzipped (previously 15 MB uncompressed); encoded uncompressed limit is 60 MiB (Limits, Source Maps are Generally Available).
Minimum Wrangler for source maps: 3.46.0 (check with wrangler --version) (Limits).
Common mistakes
Section titled “Common mistakes”- Setting only
upload_source_maps: truein Vite projects withoutbuild.sourcemapon the Worker environment—no maps are generated (Migrating fromwrangler dev). - Expecting deobfuscated stacks inside
console.log(error.stack)at runtime—they only appear in Cloudflare observability surfaces after async remapping. - Shipping client source maps to public assets on Pages or Workers sites (Debugging and logging).
- Relying on inline or broken
sourceMappingURLreferences: default Wrangler skips them; useupload_source_maps: trueonly if you want deploy to fail on unresolved maps. - Forgetting custom
build.commandpipelines (webpack, etc.): Wrangler does not run your oldtype = webpackflow automatically (Eject webpack).
How to check this on your site
Section titled “How to check this on your site”-
Run
wrangler --versionand confirm Wrangler is at least 3.46.0 (and 4.150.0+ if you rely on default uploads). See Source maps limits. -
Deploy with
wrangler deploy(orwrangler pages deploywith maps enabled for Pages) and confirm the build output contains.mapfiles for Worker code when using a custom or Vite build. -
Trigger a test exception in a preview or low-traffic route, then open remapped stacks in real-time logs or Workers Logs; for grouped failures, check Workers Issues.
-
If frames stay minified, verify
build.sourcemapfor the Worker Vite environment or strictupload_source_maps: trueto surface missing maps on deploy (Frameworks and custom builds). -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.