源码映射

了解如何在 Sentry 错误中启用可读的堆栈跟踪。

要使 Sentry 错误中的堆栈跟踪可读,您需要将源映射上传到 Sentry。 通过观看此视频或阅读以下逐步说明来学习如何解压缩您的 JavaScript 代码。

The easiest way to configure uploading source maps is by using the Sentry Wizard:

Copied
npx @sentry/wizard@latest -i sourcemaps

向导将引导您完成以下步骤:

  • 登录 Sentry 并选择一个项目
  • 安装必要的 Sentry 包
  • 配置您的构建工具以生成和上传源映射
  • 配置您的 CI 以上传源映射

If you want to configure source maps upload with Angular manually, follow the steps below.

To generate source maps, you need to add the sourceMap option to your angular.json build configuration:

angular.json
Copied
{
  // ...
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "configurations": {
            "production": {
              "sourceMap": {
                "scripts": true
              }
            }
          }
        }
      }
    }
  }
}

To upload your Angular project's source maps to Sentry, we recommend one of these options:

  • Angular CLI and Sentry webpack plugin
    Use the Angular CLI, a custom Angular builder and the Sentry webpack plugin to set releases and upload source maps automatically when running ng build.
  • Nx Angular CLI and Sentry webpack plugin
    If you're using Nx, use @nx/angular CLI and the Sentry webpack plugin to set releases and upload source maps automatically when running nx build.
  • Sentry CLI
    Upload source maps manually using the Sentry CLI.

Take a look at this guide for further options to upload source maps.