Source Maps

Upload your source maps to Sentry to enable readable stack traces in your errors.

@sentry/nitro automatically generates and uploads source maps when you build your Nitro application for production, so that errors in Sentry contain readable stack traces.

Make sure you add your auth token to your CI, if you are using one to deploy your application.

Add your auth token to your environment:

.env
Copied
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___

To configure source map uploads, provide your Sentry auth token, organization, and project slugs to the withSentryConfig wrapper:

nitro.config.ts
Copied
import { defineNitroConfig } from "nitro/config";
import { withSentryConfig } from "@sentry/nitro";

const config = defineNitroConfig({
  // your Nitro options...
});

export default withSentryConfig(config, {
  org: "___ORG_SLUG___",
  project: "___PROJECT_SLUG___",
  authToken: process.env.SENTRY_AUTH_TOKEN,
});

See how uploading source maps lets you see the exact line of code that caused an error:

When you wrap your config with withSentryConfig, the SDK:

  1. Enables source map generation if you haven't set the sourcemap option yourself
  2. Injects debug IDs into your build output
  3. Uploads source maps to Sentry after each production build
  4. Deletes .map files from the build output to avoid exposing them publicly

Source maps are only uploaded during production builds. Development builds (nitro dev) skip the upload.

If you already set sourcemap in your Nitro config, the SDK respects your setting:

  • true: the SDK uploads the generated maps
  • false: the SDK warns that errors won't be unminified and skips the upload

You can customize source map behavior in the Sentry options:

nitro.config.ts
Copied
import { defineNitroConfig } from "nitro/config";
import { withSentryConfig } from "@sentry/nitro";

const config = defineNitroConfig({
  // your Nitro options...
});

export default withSentryConfig(config, {
  org: "___ORG_SLUG___",
  project: "___PROJECT_SLUG___",
  authToken: process.env.SENTRY_AUTH_TOKEN,

  sourcemaps: {
    // Glob pattern for source map files to upload
    assets: [".output/server/**"],
    // Glob pattern for files to exclude from upload
    ignore: ["node_modules/**"],
    // Delete source maps after upload to avoid exposing them publicly
    filesToDeleteAfterUpload: [".output/server/**/*.map"],
  },
});

To disable source map uploads entirely, set sourcemaps.disable to true:

nitro.config.ts
Copied
export default withSentryConfig(config, {
  sourcemaps: {
    disable: true,
  },
});

To generate and inject debug IDs without uploading (useful if you upload maps separately), set sourcemaps.disable to "disable-upload":

nitro.config.ts
Copied
export default withSentryConfig(config, {
  sourcemaps: {
    disable: "disable-upload",
  },
});

If you're experiencing issues with source maps, see Troubleshooting Source Maps.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").