# Source maps

> Upload your build's source maps so error stacks show your original files, lines and code instead of minified bundles


import { Callout, Flow, Step, Steps, Tab, Tabs } from "@/components/docs";

See errors at `src/checkout.ts:42` instead of `index-3f9a2c.js:1:48213`.

<Flow steps={["Build", "Upload maps", "Delete them from the output", "Errors show your code"]} />

## Set it up

<Steps>
<Step title="Make an API key">

In [Organization settings → API keys](https://app.databuddy.cc/organizations/settings#api-keys), add a key with the **Source maps** preset. Add it to your CI or hosting build environment as `DATABUDDY_API_KEY`.

</Step>
<Step title="Add the plugin">

<Tabs items={["Vite", "Next.js", "Other bundlers", "curl"]}>
<Tab>

```ts title="vite.config.ts"
import { databuddySourceMaps } from "@databuddy/sdk/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [databuddySourceMaps()],
});
```

</Tab>
<Tab>

```ts title="next.config.ts"
import { withDatabuddy } from "@databuddy/sdk/next";
import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default withDatabuddy(nextConfig);
```

</Tab>
<Tab>

Build with source maps on, then upload the output folder:

```bash
npx @databuddy/sdk sourcemaps upload dist --delete
```

</Tab>
<Tab>

```bash
curl --fail-with-body --globoff -X PUT \
  -H "Authorization: Bearer $DATABUDDY_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @dist/assets/index-3f9a2c.js.map \
  "https://api.databuddy.cc/source-maps/$DATABUDDY_WEBSITE_ID/index-3f9a2c.js.map"
```

Send each `.js.map` under its own file name. `--globoff` keeps names like `[slug]-91bc0d.js.map` intact.

</Tab>
</Tabs>

</Step>
<Step title="Deploy">

Builds with the key upload their maps and delete them, so they're never served. Builds without it, such as on your laptop, stay exactly as they were.

</Step>
</Steps>

The website comes from the client ID your app already sets (`NEXT_PUBLIC_DATABUDDY_CLIENT_ID`, or `VITE_DATABUDDY_CLIENT_ID` including from `.env`). Set `DATABUDDY_WEBSITE_ID` if there's none.

| | Vite | Next.js | CLI |
|---|---|---|---|
| Versions | Vite 4+ | 13+ with webpack, 15.4.1+ with Turbopack | Any bundler |
| Turns maps on | Hidden maps, if `build.sourcemap` is unset | `productionBrowserSourceMaps` | You do |
| Deletes them after upload | Yes, even when the upload fails | Yes, even when the upload fails | With `--delete` |
| Already serving maps on purpose | Uploads and keeps them | Uploads and keeps them | Keeps them without `--delete` |

<Callout type="info">
  Needs `@databuddy/sdk` 3.10+ and Node.js 18+. Works in ES module and CommonJS configs.
</Callout>

## Options

| Plugin option | CLI flag | |
|---|---|---|
| `failOnError: true` | Exits `1` on any failure | Fail the build when an upload fails. By default it's logged and the build goes on. |
| `stripSources: true` | `--strip-sources` | Upload without your code. Frames still map to file, line and function. |
| `websiteId` | `--website-id <id>` | The website, when no client ID is set |
| | `--dry-run` | List what would upload, without a key |
| | `--concurrency <n>` | Parallel uploads, 8 by default |

Unchanged maps aren't sent again, so uploading on every deploy is cheap. For your own scripts, `uploadSourceMaps(dir)` from `@databuddy/sdk/sourcemaps` is the same uploader.

## Skip uploads if your website serves maps

When a file has no uploaded map, Databuddy reads the map its script points to (`sourceMappingURL` comment, `SourceMap` header or `data:` URL), only from your website's domain and subdomains. Uploading is still better: your code stays private, and old builds keep mapping after you deploy over them.

## Who sees your code

| | Original file, line, function | Lines of code |
|---|---|---|
| Members who can manage source maps | Yes | Yes |
| Viewers and read-only API keys | Yes | No |
| Public dashboard visitors | No | No |

Maps are stored privately with [Tigris](/data-policy#subprocessors), never served or published, and deleted with their website or organization.

## Limits

| | |
|---|---|
| One map | 25 MB, sent with `Content-Length` |
| Uploads | 2,000 an hour per website and per API key; 10 GB a day per organization. Over either: `429` with `Retry-After`. |
| File names | Letters, digits and `. _ - ~ @ + [ ]`, ending in `.js.map`, `.mjs.map` or `.cjs.map` |
| Kept for | 30 days after upload, renewed weekly while the map keeps showing errors |

## Related

- [Source maps API](https://api.databuddy.cc/): list (`GET`), delete (`DELETE`) and symbolicate (`POST /source-maps/symbolicate`)
- [API keys](/docs/api-keys)
- [Privacy](/docs/privacy)
