---
title: "Source Maps"
description: "Upload your source maps to Sentry to enable readable stack traces in your errors, along with numerous other benefits. Learn more here."
url: https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps/
---

# Source Maps | Sentry for SvelteKit

`@sentry/sveltekit` will generate and upload source maps automatically, so that errors in Sentry will contain readable stack traces.

The SvelteKit SDK uses the Sentry Vite Plugin to upload source maps. See the [Sentry Vite Plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin#options) for all available options.

## [Uploading Source Maps in a SvelteKit Project](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#uploading-source-maps-in-a-sveltekit-project)

`@sentry/sveltekit` will generate and upload source maps automatically during production builds, so that errors in Sentry contain readable stack traces.

### [Automatic Setup](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#automatic-setup)

The easiest way to configure uploading source maps is by using the [Sentry Wizard](https://docs.sentry.io/platforms/javascript/guides/sveltekit.md#step-1-install).

```bash
npx @sentry/wizard@latest -i sveltekit
```

**Note:** Source maps are only generated and uploaded during **production builds** (`npm run build`). Development builds (`npm run dev`) do not generate source maps for upload.

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

### [Manual Configuration](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#manual-configuration)

If you installed the SDK manually or the wizard failed, follow the steps below to manually configure source maps upload.

#### [1. Configure Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#1-configure-source-maps-upload)

To automatically upload source maps, you need to provide your Sentry auth token, organization, and project slugs in your Vite configuration:

**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___
```

Using environment variables in Vite configs

Vite doesn't automatically load `.env` files into `process.env` when evaluating the config file. If you store your auth token in a `.env` file and want to access it via `process.env.SENTRY_AUTH_TOKEN`, use Vite's [`loadEnv`](https://vite.dev/guide/api-javascript#loadenv) helper:

`vite.config.js`

```javascript
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "");

  return {
    plugins: [
      sentryVitePlugin({
        authToken: env.SENTRY_AUTH_TOKEN,
        // ...
      }),
    ],
  };
});
```

Alternatively, use a `.env.sentry-build-plugin` file, which the Sentry plugin reads automatically.

`vite.config.js`

```javascript
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      org: "___ORG_SLUG___",
      project: "___PROJECT_SLUG___",
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
    sveltekit(),
  ],
});
```

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

Configure source map behavior in your Vite config:

`vite.config.js`

```javascript
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      org: "___ORG_SLUG___",
      project: "___PROJECT_SLUG___",
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
    sveltekit(),
  ],
});
```

### [Override Adapter Detection](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#override-adapter-detection)

By default, `sentrySvelteKit` will try to detect your SvelteKit adapter to configure the source maps upload correctly. If you're not using one of the [supported adapters](https://docs.sentry.io/platforms/javascript/guides/sveltekit.md) or the wrong one is detected, you can override the adapter detection:

`vite.config.js`

```javascript
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      adapter: "vercel",
    }),
    sveltekit(),
  ],
});
```

### [Disable Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps.md#disable-source-maps-upload)

You can disable automatic source maps upload in your Vite config:

`vite.config.js`

```javascript
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      autoUploadSourceMaps: false,
    }),
    sveltekit(),
  ],
});
```

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

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

## [Additional Resources](https://docs.sentry.io/platforms/javascript/guides/sveltekit/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)
* [Debug Your Node.js Projects with Source Maps](https://blog.sentry.io/2019/02/20/debug-node-source-maps)

## Pages in this section

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