tracekit-source-maps
TraceKit Source Maps
When To Use
Use this skill when the user asks to:
- Upload source maps to TraceKit
- Get readable stack traces from minified JavaScript errors
- Symbolicate minified errors
- Debug production JS errors with original source code
- Set up source map integration in a CI/CD pipeline
- Fix "minified code" in error stack traces
Source maps let you see original file names, line numbers, and column numbers in stack traces instead of minified bundled code. Without source maps, production JavaScript errors show references like main.a3f2b.js:1:4523 instead of src/components/Dashboard.tsx:42:8.
Non-Negotiable Rules
- Never hardcode auth tokens in code or CI config. Always use
TRACEKIT_AUTH_TOKENenv var. - Always verify symbolication by triggering a real error and checking the stack trace shows original source.
- Source maps must match the deployed release version exactly -- the
releasein SDK init must match the--releaseused during upload. - Never serve source maps publicly in production -- upload to TraceKit only, then delete local
.mapfiles before deploying.
Prerequisites
Source maps require:
- A frontend SDK installed and initialized (
@tracekit/browser,@tracekit/react, etc.) - A build step that produces minified JavaScript (webpack, vite, rollup, esbuild, etc.)
@tracekit/clifor uploading maps (installed in Step 1)
If no frontend SDK is detected, redirect to tracekit-browser-sdk skill (or the appropriate framework skill) first.
Detection
Before applying this skill, detect the project setup:
- Check
package.jsonfor a TraceKit frontend package:@tracekit/browser,@tracekit/react,@tracekit/vue,@tracekit/angular,@tracekit/nextjs,@tracekit/nuxt- If none found, redirect to
tracekit-browser-sdkskill
- Detect build tool to determine plugin path:
vite.config.*=> Vite plugin path (Step 3A)webpack.config.*=> Webpack plugin path (Step 3B)- Neither => CLI-only path (Step 3C)
Step 1: Install TraceKit CLI
npm install -D @tracekit/cli
The CLI is used for uploading source maps to TraceKit. Install it as a dev dependency so it is available in your build pipeline.
Step 2: Configure Auth Token
Source map uploads require an auth token (separate from the API key used in the SDK).
Get your auth token:
- Log in to TraceKit
- Go to Settings > Auth Tokens
- Click "Create Token"
- Select the
releases:writescope - Copy the generated token
Set the environment variable:
export TRACEKIT_AUTH_TOKEN=your_auth_token_here
Add to your .env file for local development. For CI, add it as a repository secret (see Step 5).
Do not commit auth tokens. Use .env files, CI secrets, or deployment secret managers.
Step 3: Build Plugin Setup
Choose the path matching your build tool. The build plugin automatically uploads source maps after each build.
Path A: Vite
Install the Vite plugin:
npm install -D @tracekit/vite-plugin
Configure in vite.config.ts:
// vite.config.ts
import { defineConfig } from 'vite';
import { traceKitSourceMaps } from '@tracekit/vite-plugin';
export default defineConfig({
build: {
sourcemap: true, // Required: generate source maps
},
plugins: [
traceKitSourceMaps({
authToken: process.env.TRACEKIT_AUTH_TOKEN,
release: process.env.npm_package_version,
cleanArtifacts: true, // Delete .map files after upload
}),
],
});
Path B: Webpack
Install the Webpack plugin:
npm install -D @tracekit/webpack-plugin
Configure in webpack.config.js:
// webpack.config.js
const { TraceKitSourceMapPlugin } = require('@tracekit/webpack-plugin');
module.exports = {
devtool: 'source-map', // Required: generate source maps
plugins: [
new TraceKitSourceMapPlugin({
authToken: process.env.TRACEKIT_AUTH_TOKEN,
release: process.env.npm_package_version,
cleanArtifacts: true, // Delete .map files after upload
}),
],
};
Path C: CLI Only (Rollup, esbuild, or custom)
If you use a build tool without a dedicated plugin, upload source maps manually via the CLI after building:
- Ensure your build generates source maps (consult your bundler docs).
- Upload after build:
npx tracekit-cli sourcemaps upload \
--auth-token=$TRACEKIT_AUTH_TOKEN \
--release=$(node -p "require('./package.json').version") \
./dist
- Delete source maps before deploying:
find ./dist -name "*.map" -delete
Step 4: Release Association
The release value must match between your SDK init and the source map upload. This is how TraceKit maps errors to the correct source maps.
import { init } from '@tracekit/browser';
init({
apiKey: import.meta.env.VITE_TRACEKIT_API_KEY,
serviceName: 'my-frontend-app',
endpoint: 'https://app.tracekit.dev/v1/traces',
enableCodeMonitoring: true,
release: import.meta.env.VITE_APP_VERSION || '0.0.0', // Must match upload --release
});
Common release strategies:
package.jsonversion --process.env.npm_package_version(e.g.,1.2.3)- Git SHA --
process.env.GITHUB_SHAor output ofgit rev-parse HEAD(e.g.,a1b2c3d) - Build timestamp -- less common, harder to correlate
Pick one strategy and use it consistently in both SDK init and source map upload.
Step 5: CI Pipeline Integration
Automate source map uploads in your deployment pipeline. Here is a complete GitHub Actions workflow:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # https://github.com/actions/checkout
- uses: actions/setup-node@v4 # https://github.com/actions/setup-node
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload source maps to TraceKit
run: |
npx tracekit-cli sourcemaps upload \
--auth-token=$TRACEKIT_AUTH_TOKEN \
--release=${{ github.sha }} \
./dist
env:
TRACEKIT_AUTH_TOKEN: ${{ secrets.TRACEKIT_AUTH_TOKEN }}
- name: Delete local source maps
run: find ./dist -name "*.map" -delete
- name: Deploy
run: echo "Your deploy command here (e.g., aws s3 sync, vercel deploy, etc.)"
Setup required:
- Go to your GitHub repo > Settings > Secrets and variables > Actions
- Add a new secret:
TRACEKIT_AUTH_TOKENwith your auth token value - Update the
releasevalue in your SDK init to useprocess.env.GITHUB_SHA(or match whatever you pass to--release)
For other CI providers, the pattern is the same:
- Install dependencies
- Build (with source maps enabled)
- Upload source maps via CLI
- Delete
.mapfiles - Deploy
Step 6: Verification
Verify source maps are working end to end:
- Build your application -- you should see "Source maps uploaded successfully" in the build output (if using a plugin) or after the CLI upload command
- Deploy the built application (without
.mapfiles) - Trigger a JavaScript error -- add this temporarily:
import { captureException } from '@tracekit/browser'; setTimeout(() => { captureException(new Error('Source map test error')); }, 2000); - Visit
https://app.tracekit.dev/issuesand find the error - Check the stack trace -- it should show:
- Original file names (e.g.,
src/components/Dashboard.tsx) - Original line numbers and column numbers
- Original function names
- NOT minified references like
main.a3f2b.js:1:4523
- Original file names (e.g.,
- Remove the test error code once verified
Troubleshooting
Stack trace still shows minified code
- Check release version matches -- the
releaseininit()must exactly match the--releaseused during upload. Print both to verify. - Check source maps were generated -- verify
.mapfiles exist in your build output directory before upload. For Vite:build: { sourcemap: true }. For Webpack:devtool: 'source-map'. - Check upload succeeded -- run
npx tracekit-cli sourcemaps list --release=YOUR_RELEASEto verify maps are uploaded.
"Source map not found" warning in dashboard
- Check upload included all
.mapfiles -- the CLI uploads all.mapfiles in the specified directory recursively. - Check file paths match -- source map file names must correspond to the deployed JS file names.
- Check the release exists -- go to Dashboard > Releases and verify the release version appears.
Auth token errors during upload
- Verify token has
releases:writescope -- tokens without this scope cannot upload source maps. - Check
TRACEKIT_AUTH_TOKENis set -- runecho $TRACEKIT_AUTH_TOKENto verify (should not be empty). - Check token is not expired -- auth tokens can have expiration dates. Generate a new one if needed.
CI upload fails
- Check
TRACEKIT_AUTH_TOKENsecret is set in your CI provider's secret management (GitHub: Settings > Secrets > Actions). - Check build output directory -- ensure
./dist(or your output dir) contains.mapfiles before the upload step. - Check network access -- CI runners must reach
https://app.tracekit.dev.
Next Steps
Once source maps are working, consider:
- Releases (
tracekit-releasesskill) -- Track deployments with version metadata and deploy notifications - Alerts (
tracekit-alertsskill) -- Get notified when new error types appear or error rates spike after a deploy
References
- Source maps docs:
https://app.tracekit.dev/docs/frontend/source-maps - TraceKit CLI docs:
https://app.tracekit.dev/docs/cli - TraceKit docs root:
https://app.tracekit.dev/docs - Dashboard:
https://app.tracekit.dev