Source maps and stack traces
Stack traces 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.
源映射
要启用源映射,请在 wrangler pages deploy
中提供--upload-source-maps
标记,或者在 Pages 应用程序的 wrangler.toml
文件中添加以下内容(如果使用的是 Pages 编译环境):
启用上传源映射后,Wrangler 会在运行 wrangler pages deploy
时自动生成并上传源映射文件。
堆栈跟踪
当应用程序抛出未捕获异常时,我们会获取源映射,并利用它将异常的堆栈跟踪映射回应用程序的原始源代码行。
然后,你就可以在流式传输 实时日志 时查看堆栈跟踪。
相关资源
- 实时日志 - 了解如何实时捕捉 Pages 日志。