---
title: "Source Maps"
description: "Upload your source maps to Sentry to enable readable stack traces in your errors."
url: https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps/
---

# Source Maps | Sentry for Nitro

`@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`

```bash
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`

```typescript
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,
});
```

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

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

## [How Source Maps Work in Nitro](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps.md#how-source-maps-work-in-nitro)

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

### [Source Map Options](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps.md#source-map-options)

You can customize source map behavior in the Sentry options:

`nitro.config.ts`

```typescript
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"],
  },
});
```

### [Disabling Source Map Uploads](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps.md#disabling-source-map-uploads)

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

`nitro.config.ts`

```typescript
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`

```typescript
export default withSentryConfig(config, {
  sourcemaps: {
    disable: "disable-upload",
  },
});
```

### [Troubleshooting](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps.md#troubleshooting)

If you're experiencing issues with source maps, see [Troubleshooting Source Maps](https://docs.sentry.io/platforms/javascript/guides/nitro/troubleshooting.md).

## [Additional Resources](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps.md#additional-resources)

* [Using sentry-cli to Upload Source Maps](https://docs.sentry.io/cli/releases.md#sentry-cli-sourcemaps)
* [4 Reasons Why Your Source Maps Are Broken](https://blog.sentry.io/2018/10/18/4-reasons-why-your-source-maps-are-broken)

## Pages in this section

- [Troubleshooting Source Maps](https://docs.sentry.io/platforms/javascript/guides/nitro/sourcemaps/troubleshooting_js.md)
