Source Map Upload
Upload a build's source maps to Sophonz per web version, so production stack traces resolve to original files and line numbers.
An error in a minified bundle reads like onClick@chunks/36o8zuzlzx381.js:1:918. With that build's source maps uploaded, the log and trace views show onClick app/client-probes.tsx:43:19 and the line of code instead. Source maps are kept per web version, and a stack trace is resolved with the maps of the web version it reported when you open it.
Web version
The web version is the version of the web build itself. The Browser SDK (2.1.0 and later) sends the appVersion passed to init as the resource attribute web.version, and source maps are matched on that value.
| Running in | service.version | web.version |
|---|---|---|
| A browser | appVersion | appVersion |
| A native app's WebView | The native app's version (set by the bridge) | The page's own appVersion |
In a WebView the native bridge replaces service.version with the app's version, but web.version keeps the page's value. That is what lets each web deploy keep its own source maps even when the web ships far more often than the app. See WebView integration.
CAUTION — Upload under the version the SDK reports
Source maps only fit the scripts of the build they came from. Set the SDK's appVersion and the upload's web version from one variable in CI. If they differ, the upload succeeds and stack traces still stay unreadable.
There are two ways to upload:
@sophonz/cli: uploads a build output directory from any bundler — Next.js, webpack, Rollup, esbuild.@sophonz/vite-sourcemap: uploads automatically when a Vite build finishes.
@sophonz/cli
Installation
npm install @sophonz/cli --save-devRequires Node.js 20 or later. npx @sophonz/cli works without installing.
Usage
export SOPHONZ_TOKEN=sophonz_pat_...
npx @sophonz/cli upload-sourcemaps \
--path dist \
--web-version 2026.09.15-1Next.js serves its scripts from /_next/static, so pass a prefix. Enable source maps with productionBrowserSourceMaps: true in next.config.
npx @sophonz/cli upload-sourcemaps \
--path .next/static \
--url-prefix _next/static \
--web-version "$WEB_VERSION"| Option | Environment | Description |
|---|---|---|
-p, --path | — | Directory to search for source maps (required) |
-w, --web-version | — | Web version; the same value as the SDK's appVersion (required) |
--url-prefix | — | URL path the scripts are served under, e.g. _next/static |
-t, --token | SOPHONZ_TOKEN | App access token |
--api-url | SOPHONZ_API_URL | Defaults to https://app.sophonz.ai |
--dry-run | — | Print what would be uploaded without uploading |
Pairing scripts with source maps
The CLI reads the //# sourceMappingURL= comment at the end of each script and uploads the map under the script's path, because a stack trace only ever names the script.
This also covers bundlers that name a map differently from its script: Next.js 16 (Turbopack) writes the map of 36o8zuzlzx381.js as 1-1m44t1taogc.js.map. Inline (data:) maps are extracted and uploaded too, and a .js.map no script references is uploaded under its own name.
--dry-run shows how each map was paired:
[sophonz] 8 source map(s) for web version 1.4.0 → https://app.sophonz.ai
(dry run) _next/static/chunks/36o8zuzlzx381.js.map ← chunks/1-1m44t1taogc.js.map@sophonz/vite-sourcemap plugin
Features
- Uploads source maps automatically after a Vite build
- Include/exclude patterns
- gzip compression
- Bundle mode: one tar.gz for all maps, one request
- Concurrency limit and retries
- CI detection, optional deletion of local maps after upload
- Custom path transforms and URL prefixes
Installation
npm install @sophonz/vite-sourcemap --save-devBasic configuration
// vite.config.ts
import { defineConfig } from 'vite'
import sourcemapUpload from '@sophonz/vite-sourcemap'
export default defineConfig({
build: {
sourcemap: true, // required: source maps must be generated
},
plugins: [
sourcemapUpload({
endpoint: 'https://app.sophonz.ai/api/v1/web-sourcemaps',
apiKey: process.env.SOPHONZ_TOKEN,
// Web version: the same value as the SDK's init appVersion
appVersion: process.env.WEB_VERSION,
}),
],
})NOTE — What goes in apiKey
apiKey takes a Sophonz access token issued for one app. See Issuing access tokens.
Advanced configuration
// vite.config.ts
import { defineConfig } from 'vite'
import sourcemapUpload from '@sophonz/vite-sourcemap'
export default defineConfig({
build: {
sourcemap: true,
},
plugins: [
sourcemapUpload({
endpoint: 'https://app.sophonz.ai/api/v1/web-sourcemaps',
apiKey: process.env.SOPHONZ_TOKEN,
// Web version. Maps are kept under this value
appVersion: process.env.WEB_VERSION,
build: process.env.GIT_SHA,
// Filtering (applied to paths relative to the output directory)
include: [/assets\/.+\.js\.map$/],
exclude: [/node_modules/],
// When scripts are served from a path that differs from the output layout
urlPrefix: 'static/js',
// Upload behavior
concurrency: 3,
retries: 5,
gzip: true,
deleteAfterUpload: true,
// Only run in CI
ciOnly: true,
}),
],
})To cut the number of requests for builds with many maps, use bundle mode: every map goes into one tar.gz and one request.
sourcemapUpload({
endpoint: 'https://app.sophonz.ai/api/v1/web-sourcemaps',
apiKey: process.env.SOPHONZ_TOKEN,
appVersion: process.env.WEB_VERSION,
bundle: true,
bundleFilename: 'sourcemaps.tar.gz',
})Configuration options
Required
| Option | Type | Description |
|---|---|---|
endpoint | string | API endpoint to upload to |
Optional
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | - | Access token, sent as Authorization: Bearer <token> |
appVersion | string | - | Web version; maps are kept and matched under it |
release | string | - | Used as the web version when appVersion is unset |
build | string | - | Build number or commit SHA, recorded as the build ID |
method | 'POST' | 'PUT' | 'POST' | HTTP method. The Sophonz endpoint accepts POST only |
headers | Record<string, string> | {} | Extra HTTP headers |
appType | 'ANDROID' | 'IOS' | 'WEB' | 'ALL' | null | null | Platform hint. Not used by the current endpoint |
fileFieldName | string | 'file' | Form field for the file. The Sophonz endpoint requires file |
fields | Record<string, string | number | boolean> | {} | Extra form fields |
include | (string | RegExp)[] | - | Files to include. Strings are regex sources, not globs |
exclude | (string | RegExp)[] | - | Files to exclude |
urlPrefix | string | - | Prefix for the logical path (name/path fields) |
transformPath | (path: string) => string | - | Logical path transform. Overrides urlPrefix |
concurrency | number | 6 | Parallel uploads |
retries | number | 3 | Retries when an upload throws (exponential backoff) |
gzip | boolean | true | gzip before upload |
bundle | boolean | false | Upload all maps as one tar.gz |
bundleFilename | string | 'sourcemaps.tar.gz' | Archive name in bundle mode |
deleteAfterUpload | boolean | false | Delete local .map files after a successful upload |
ciOnly | boolean | false | Only run in CI |
verbose | boolean | true in CI, false locally | Detailed logging |
CAUTION — A failed upload does not fail the build
When the server returns an error, the plugin logs it and the build carries on. To make the upload a condition of a green build, run @sophonz/cli as its own step; it exits with code 1 on failure.
NOTE — Map names from other bundlers
The plugin sends each .map file's output path as its logical path. That matches for bundlers like Vite, where a map is named after its script plus .map. For bundlers that name maps differently, use @sophonz/cli.
Upload endpoint
POST https://app.sophonz.ai/api/v1/web-sourcemaps
Authorization: Bearer sophonz_pat_...
Content-Type: multipart/form-datahttps://app.sophonz.com/api/v1/web-sourcemaps serves the same endpoint.
Request fields
| Field | Description |
|---|---|
file | The source map. gzip-compressed content when contentEncoding=gzip |
path, name | Logical path. Matched against the end of a stack frame's script URL |
webVersion | Web version |
appVersion | Web version when webVersion is absent |
release | Web version when both are absent; unreleased when all three are |
build | Build ID |
contentEncoding | gzip when compressed |
bundle, bundleFormat, fileCount | Bundle mode only |
Nothing in the request names the app. That is why tokens work the way they do below.
Response
A successful upload returns 201 with where the map was stored:
{
"ok": true,
"key": "sourcemaps/<orgId>/<projectId>/<appId>/web/1.4.0/assets/app.js.map",
"app": "next-sample",
"serviceNamespace": "sophonz",
"release": "unreleased",
"version": "1.4.0",
"bundle": false,
"fileCount": null
}key has the form sourcemaps/<org id>/<project id>/<app id>/web/<web version>/<logical path>. Uploading the same path again for the same web version replaces it.
Limits and errors
- One upload may be up to 200MB. In bundle mode the whole compressed archive counts.
- Source maps are stored privately. They contain your original source, so do not ship them to a public bucket or CDN.
| Status | Cause |
|---|---|
401 | Token missing, invalid, expired or revoked |
400 | Not multipart, no file field, or an empty file |
413 | File larger than 200MB |
500 | The server could not store the map |
Issuing access tokens
Uploads need a Sophonz access token, and tokens exist per app only. The upload request names no app, so the token is what says which app the maps belong to.
Issue from the console
- Sign in to
https://app.sophonz.ai - Open Settings
- Select the project and the app
- In Access tokens, enter a name and an expiry (never / 30 days / 90 days / 1 year) and create it
- The token is shown once. Copy it from this screen
Tokens look like sophonz_pat_<random>.
CAUTION — The token is shown once
Once you leave the screen the token cannot be shown again; the list keeps only its last four characters, last use and expiry. Keep it in your CI's secrets.
Revocation takes effect immediately and cannot be undone. To rotate, issue the new token, update CI, then revoke the old one.
Checking uploads
Settings > project > app > Mapping files lists the app's versions. The list fills in from telemetry, and each web version shows how many source maps it has.
- A web version that has sent telemetry but has no maps is flagged: its stack traces cannot be resolved.
- A web version uploaded before release appears in the list before any telemetry arrives.
When an error comes in, expand its row in Logs or Traces. The stack trace viewer shows the original file, line number and the line of code. Without maps it shows "No mapping file for version X".
Per-platform source maps (appType)
appType accepts 'ANDROID' | 'IOS' | 'WEB' | 'ALL' | null and is sent as a form field, but the current endpoint does not use it. Maps are kept by app and web version only.
If one app ships different bundles per platform, give them different web versions — 2026.09.15-1-android, for example — and set each bundle's SDK appVersion to match.
Using with GitHub Actions
The CLI as its own step, with one web version variable feeding both the build and the upload:
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
env:
WEB_VERSION: ${{ github.run_number }}-${{ github.sha }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- name: Build
# The app passes this to Sophonz.init({ appVersion })
env:
NEXT_PUBLIC_WEB_VERSION: ${{ env.WEB_VERSION }}
run: npm run build
- name: Upload source maps
env:
SOPHONZ_TOKEN: ${{ secrets.SOPHONZ_TOKEN }}
run: npx @sophonz/cli upload-sourcemaps --path .next/static --url-prefix _next/static --web-version "$WEB_VERSION"With the Vite plugin, skip the upload step and pass SOPHONZ_TOKEN and WEB_VERSION to npm run build.
CI environment detection
The Vite plugin treats the build as CI when any of these is set. It decides ciOnly and the default of verbose.
CIGITHUB_ACTIONSGITLAB_CIBUILDKITECIRCLECITRAVISBITBUCKET_BUILD_NUMBER