Cloudflare Docs
Workers
Edit this page on GitHub
Set theme to dark (⇧+D)

Source maps and stack traces

Beta

Stack traces help with debugging your code when the Worker 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 – not just on Workers, but across platforms – 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.

​​ Source Maps

To enable source maps, add the following to your Worker’s wrangler.toml file:

upload_source_maps = true

When upload_source_maps is set to true, Wrangler will automatically generate and upload source map files when you run wrangler deploy or wrangler versions deploy. ​​

​​ 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 stack trace in when streaming real-time logs or in Tail Workers.

  • Tail Workers - Learn how to attach Tail Workers to transform your logs and send them to HTTP endpoints.
  • Real-time logs - Learn how to capture Workers logs in real-time.