---
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/svelte/sourcemaps/
---

# Source Maps | Sentry for Svelte

To enable readable stack traces in your Sentry errors, you need to upload your source maps to [Sentry](https://sentry.io/welcome/).

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

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

## [Upload Source Maps for a Svelte Project](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps.md#upload-source-maps-for-a-svelte-project)

This guide assumes you are using the `@sentry/svelte` SDK on version `7.47.0` or higher.

If you are on an older version and you want to upload source maps we recommend upgrading your SDK to the newest version.

### [Using the Sentry Wizard](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps.md#using-the-sentry-wizard)

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

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

The wizard will guide you through the following steps:

* Logging into Sentry and selecting a project
* Installing the necessary Sentry packages
* Configuring your build tool to generate and upload source maps
* Configuring your CI to upload source maps

If you want to configure source maps upload manually, follow the guide for your bundler or build tool below.

### [Manually Configuring Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps.md#manually-configuring-source-maps-upload)

To generate source maps with your Svelte project, you need to set the source map [compiler options](https://svelte.dev/docs#compile-time-svelte-compile) in your Svelte config:

`svelte.config.js`

```JavaScript
import sveltePreprocess from "svelte-preprocess";

const config = {
  compilerOptions: {
    enableSourcemap: true,
  },
  preprocess: sveltePreprocess({
    sourceMap: true,
  }),
};

export default config;
```

If you're using Vite in you Svelte project, you can use Sentry's Vite plugin for convenience:

```bash
npm install @sentry/vite-plugin --save-dev
```

To upload source maps you have to configure an [Organization Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/).

Alternatively, you can also use a [Personal Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/account/api/auth-tokens/), with the "Project: Read & Write" and "Release: Admin" permissions.

Auth tokens can be passed to the plugin explicitly with the `authToken` option, with a `SENTRY_AUTH_TOKEN` environment variable, or with a `.env.sentry-build-plugin` file in the working directory when building your project. You likely want to add the auth token as an environment variable to your CI/CD environment.

`.env.sentry-build-plugin`

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

Configure Vite to emit source maps and use the Sentry Vite plugin:

`vite.config.js`

```JavaScript
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { sentryVitePlugin } from "@sentry/vite-plugin";

export default defineConfig({
  build: {
    sourcemap: "hidden", // Source map generation must be turned on ("hidden", true, etc.)
  },
  plugins: [
    svelte(),

    // Put the Sentry Vite plugin after all other plugins
    sentryVitePlugin({
      org: "___ORG_SLUG___",
      project: "___PROJECT_SLUG___",
      authToken: process.env.SENTRY_AUTH_TOKEN,

      sourcemaps: {
        // As you're enabling client source maps, you probably want to delete them after they're uploaded to Sentry.
        // Set the appropriate glob pattern for your output folder - some glob examples below:
        filesToDeleteAfterUpload: ["./**/*.map", ".*/**/public/**/*.map", "./dist/**/client/**/*.map"]
      }
    }),
  ],
});
```

Generating source maps **may expose them to the public**, potentially causing your source code to be leaked. You can prevent this by configuring your server to deny access to `.js.map` files, or by using [Sentry Vite Plugin's `sourcemaps.filesToDeleteAfterUpload`](https://www.npmjs.com/package/@sentry/vite-plugin#sourcemapsfilestodeleteafterupload) option to delete source maps after they've been uploaded to Sentry.

The Sentry Vite plugin doesn't upload source maps in watch-mode/development-mode. We recommend running a production build to test your implementation.

### [Other Bundlers](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps.md#other-bundlers)

If you're using a bundler other than Vite, check out our general guide on how to [upload source maps](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/uploading.md), or refer to your bundler's documentation.

By default, if Sentry can't find the uploaded files it needs, it will attempt to download them from the URLs in the stack trace. To disable this, turn off "Enable JavaScript source fetching" in either your organization's "Security & Privacy" settings or your project's general settings.

## [Additional Resources](https://docs.sentry.io/platforms/javascript/guides/svelte/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

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