# Readable stack traces for minified JavaScript

A production build squeezes your code into a few files with one long line each, so a browser error points at something like `app-3f9a1c.js:1:23456`. That's no help at 2 a.m. Upload the build's source maps and Tailcove reads them when you open the error: each frame shows your own file, line and function, the code around it, a **View on GitHub** link to that line at the commit you deployed, and **Open in VS Code**. This guide sets that up for a Vite or webpack app. The details are in [Code links and source maps](https://tailcove.dev/docs/code-links).

## 1. Build source maps, but don't serve them

Turn maps on for the production build, in the "hidden" form, so the bundles don't point browsers at them.

Vite, in `vite.config.ts`:

```ts
export default defineConfig({
  build: {
    sourcemap: 'hidden',
  },
});
```

webpack, in `webpack.config.js`:

```js
module.exports = {
  mode: 'production',
  devtool: 'hidden-source-map',
};
```

Both write a `.map` file next to each bundle. Keep the default content hashes in the file names (`app-3f9a1c.js`): Tailcove finds the map for a frame by the path of the script's URL, and a hashed name makes each build's path unique, so you don't need to tag maps with a release.

## 2. Upload them from CI, then delete them

In **Settings → API tokens**, make a token with the **For CI** preset and add it to GitHub as the secret `TAILCOVE_API_TOKEN`. Then, after the build step:

```yaml
      - name: Install tailcove
        run: |
          curl -fsSL https://github.com/tailcove/agent/releases/latest/download/tailcove_linux_amd64.tar.gz | tar -xz tailcove
          sudo install -m 0755 tailcove /usr/local/bin/tailcove

      - name: Upload source maps
        env:
          TAILCOVE_API_TOKEN: ${{ secrets.TAILCOVE_API_TOKEN }}
        run: tailcove sourcemaps upload dist/assets --source web --url-prefix https://app.example.com/assets

      - name: Keep the maps off the server
        run: find dist -name '*.map' -delete
```

`--url-prefix` is where the folder is served from. Each map is filed under the prefix plus its path inside the folder, so `dist/assets/app-3f9a1c.js.map` belongs to `https://app.example.com/assets/app-3f9a1c.js`. The last step deletes the maps before the deploy, so your original code isn't downloadable from your site. Tailcove keeps its copies private.

Upload before the deploy goes live, so the first errors after it are already readable.

## 3. Point the links at your repository

Open the source's **Issues** tab and choose its **GitHub repository**. That's enough for **View on GitHub**: each in-app frame links to its line at the commit of the latest [deploy](https://tailcove.dev/docs/deploy-checks) recorded before the error, or at the default branch when there's none.

If a path in your maps carries a folder that isn't in the repository, add it under **Path prefixes to remove** on the **Code links** card of the source's **Settings** tab. Common ones are added for you: `webpack://app/./src/cart.ts` and `../../src/cart.ts` both become `src/cart.ts`. For GitLab, Bitbucket or another host, set a **Link template** there, such as `https://gitlab.com/acme/web/-/blob/{commit}/{path}#L{line}`.

## 4. Check it worked

Wait for a browser error from the new build, or cause one from your own code: an error typed into the browser console
won't do, because that code isn't part of the bundle. A throwaway button is enough:

```js
document.querySelector('#checkout')?.addEventListener('dblclick', () => {
  throw new Error('source map check');
});
```

Open the error from the source's **Issues** tab or its log line. The top frame now reads like `src/cart.ts:42:7` in `addToCart`, with the minified location under it and a few lines of your code around the failing one. **View on GitHub** opens that line.

The first time you press **Open in VS Code**, Tailcove asks where the repository is checked out on your computer, like `/Users/you/code/web`. Your browser remembers it for that source, and the button opens the file at the line.

## FAQ

**Do I need to tag maps with a release?**

Not when your file names have content hashes, which Vite and webpack add by default. `--release` is there for builds that reuse the same file name: an error that carries a release uses the map uploaded for it, and otherwise the newest map for that path wins.

**How many maps can a source hold?**

It depends on the plan: 50 on Free, 2,000 on Pro and 10,000 on Business, each map at most 25 MB. Maps are deleted 90 days after they're uploaded, and **Delete all** on the **Code links** card clears them at once.

**My frames still show minified code. What's wrong?**

Usually the URL. The path of the script in the error has to match a path you uploaded, so check `--url-prefix` against where the files are really served from. Run `tailcove sourcemaps upload` again after fixing it; a new upload for the same path replaces the old one.

**Does this work for React Native or Node?**

Node stack traces already name your files, so they need no maps, only the repository link. React Native bundles aren't matched to maps yet.
