---
description: Adding source maps and generating stack traces for Workers.
title: Source maps and stack traces
image: https://developers.cloudflare.com/workers/observability/source-maps/og.png?v=85876e94290d3ccd
---

[Skip to content](#main-content)

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt  
> Use this file to discover all available pages before exploring further.

# Source maps and stack traces

Last updated Oct 23, 2026|Copy as Markdown| [View as Markdown](https://developers.cloudflare.com/workers/observability/source-maps/index.md)| [Agent setup](https://developers.cloudflare.com/agent-setup/)

[Stack traces ↗︎](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack) help with debugging your code when your application encounters an unhandled exception. Stack traces show you the specific functions that were called, in what order, from which line and file, and with what arguments.

Most JavaScript code is first bundled, often transpiled, and then minified before being deployed to production. This process creates smaller bundles to optimize performance and converts code from TypeScript to Javascript if needed.

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.

## Enable source maps

Source maps are uploaded by default from Wrangler 4.150.0. When you run [`wrangler deploy`](https://developers.cloudflare.com/workers/wrangler/commands/general/#deploy), [`wrangler versions upload`](https://developers.cloudflare.com/workers/wrangler/commands/general/#versions-upload), or [`wrangler preview`](https://developers.cloudflare.com/workers/wrangler/commands/workers/#preview), Wrangler generates and uploads source maps for your Worker, so stack traces show original file names and line numbers without any configuration.

By default, Wrangler skips source maps it cannot resolve, such as inline `data:` source maps or a `sourceMappingURL` that points to a missing file, and continues the upload. To fail the upload instead, set `upload_source_maps` to `true` in your Worker's [Wrangler configuration](https://developers.cloudflare.com/workers/wrangler/configuration/):

```jsonc
{
	"upload_source_maps": true
}
```

```toml
upload_source_maps = true
```

On earlier versions of Wrangler, source maps are only uploaded when `upload_source_maps` is set to `true`.

[`cf deploy`](https://developers.cloudflare.com/cf/) also uploads source maps by default. It uploads every source map in the build output, and `cf build` generates them for Workers built with the Cloudflare Vite plugin 1.64.0 or later, or with Wrangler 4.151.0 or later. To opt out, [disable source maps](#disable-source-maps) in your build.

Note

Miniflare can also [output source maps ↗︎](https://miniflare.dev/developing/source-maps) for use in local development or [testing](https://developers.cloudflare.com/workers/testing/miniflare/writing-tests).

### Frameworks and custom builds

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.

The [Cloudflare Vite plugin](https://developers.cloudflare.com/workers/vite-plugin/) generates external maps for your [Worker environment](https://developers.cloudflare.com/workers/vite-plugin/reference/vite-environments/) by default from version 1.64.0, unless you set Vite's `build.sourcemap` or the Worker's `upload_source_maps`. Maps are not added to the client environment, so they do not end up in your public assets.

On earlier versions, enable external maps for your Worker environment. For a Worker environment named `my_worker`, use:

*vite.config.tsts*

```ts
import { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";

export default defineConfig({
	plugins: [cloudflare()],
	environments: {
		my_worker: {
			build: { sourcemap: true },
		},
	},
});
```

Use `ssr` when your framework assigns the Worker to that environment. The plugin adds `upload_source_maps: true` to its output configuration when map generation is enabled. An explicit `upload_source_maps: false` disables uploads.

For other build tools, emit external map files and preserve their `sourceMappingURL` references in the generated JavaScript. Keep server maps out of your public assets directory.

### Disable source maps

To disable uploads, set `upload_source_maps` to `false`:

```jsonc
{
	"upload_source_maps": false
}
```

```toml
upload_source_maps = false
```

You can also pass `--no-upload-source-maps` to `wrangler deploy` or `wrangler versions upload`.

With the Cloudflare Vite plugin, you can instead set `build.sourcemap` to `false` for the Worker environment. `cf deploy` uploads every source map in the build output, so with a `cf` project, turn off source map generation in your build to opt out.

## Stack traces

​​ When your Worker throws an uncaught exception, we fetch the source map and use it to map the stack trace of the exception back to lines of your Worker’s original source code.

You can then view the source-mapped stack trace when streaming [real-time logs](https://developers.cloudflare.com/workers/observability/logs/real-time-logs/) or in [Tail Workers](https://developers.cloudflare.com/workers/observability/logs/tail-workers/).

[Workers Issues](https://developers.cloudflare.com/workers/observability/issues/) groups production failures and displays captured stack traces when available.

Note

The source map is retrieved after your Worker invocation completes — it's an asynchronous process that does not impact your Worker's CPU utilization or performance. Source maps are not accessible inside the Worker at runtime, if you `console.log()` the [stack property ↗︎](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack) within a Worker, you will not get a deobfuscated stack trace.

When Cloudflare attempts to remap a stack trace to the Worker's source map, it does so line-by-line, remapping as much as possible. If a line of the stack trace cannot be remapped for any reason, Cloudflare will leave that line of the stack trace unchanged, and continue to the next line of the stack trace.

## Limits

Wrangler version

Minimum required Wrangler version for source maps: 3.46.0. Check your version by running `wrangler --version`.

| Description | Limit |
| --- | --- |
| Maximum source map size, gzipped | 15 MiB |
| Maximum source map size, encoded (uncompressed) | 60 MiB |

## Example

Consider a simple project. `src/index.ts` serves as the entrypoint of the application and `src/calculator.ts` defines a ComplexCalculator class that supports basic arithmetic.

- wrangler.jsonc
- tsconfig.json
- src
  - calculator.ts
  - index.ts

Let's see how source maps can simplify debugging an error in the ComplexCalculator class.

![Stack Trace without Source Map remapping](https://developers.cloudflare.com/cdn-cgi/image/onerror=redirect,width=1908,height=198,format=webp/_astro/without-source-map.ByYR83oU.png)

With **no source maps uploaded**: notice how all the Javascript has been minified to one file, so the stack trace is missing information on file name, shows incorrect line numbers, and incorrectly references `js` instead of `ts`.

![Stack Trace with Source Map remapping](https://developers.cloudflare.com/cdn-cgi/image/onerror=redirect,width=1850,height=238,format=webp/_astro/with-source-map.PipytmVe.png)

With **source maps uploaded**: all methods reference the correct files and line numbers.

## Related resources

- [Tail Workers](https://developers.cloudflare.com/workers/observability/logs/tail-workers/) - Learn how to attach Tail Workers to transform your logs and send them to HTTP endpoints.
- [Real-time logs](https://developers.cloudflare.com/workers/observability/logs/real-time-logs/) - Learn how to capture Workers logs in real-time.
- [RPC error handling](https://developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/) - Learn how exceptions are handled over RPC (Remote Procedure Call).

Was this helpful?

YesNo

## On this page

[![](https://developers.cloudflare.com/_astro/logo.te5VL_aD.svg)Docs](https://developers.cloudflare.com/)

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/observability/source-maps/#page","headline":"Source maps and stack traces","description":"Adding source maps and generating stack traces for Workers.","url":"https://developers.cloudflare.com/workers/observability/source-maps/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/observability/source-maps/og.png?v=85876e94290d3ccd","dateModified":"2026-10-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
