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 inservice.versionweb.version
A browserappVersionappVersion
A native app's WebViewThe 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

NPM Version

Installation

npm install @sophonz/cli --save-dev

Requires 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-1

Next.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"
OptionEnvironmentDescription
-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, --tokenSOPHONZ_TOKENApp access token
--api-urlSOPHONZ_API_URLDefaults 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

NPM Version

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-dev

Basic 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

OptionTypeDescription
endpointstringAPI endpoint to upload to

Optional

OptionTypeDefaultDescription
apiKeystring-Access token, sent as Authorization: Bearer <token>
appVersionstring-Web version; maps are kept and matched under it
releasestring-Used as the web version when appVersion is unset
buildstring-Build number or commit SHA, recorded as the build ID
method'POST' | 'PUT''POST'HTTP method. The Sophonz endpoint accepts POST only
headersRecord<string, string>{}Extra HTTP headers
appType'ANDROID' | 'IOS' | 'WEB' | 'ALL' | nullnullPlatform hint. Not used by the current endpoint
fileFieldNamestring'file'Form field for the file. The Sophonz endpoint requires file
fieldsRecord<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
urlPrefixstring-Prefix for the logical path (name/path fields)
transformPath(path: string) => string-Logical path transform. Overrides urlPrefix
concurrencynumber6Parallel uploads
retriesnumber3Retries when an upload throws (exponential backoff)
gzipbooleantruegzip before upload
bundlebooleanfalseUpload all maps as one tar.gz
bundleFilenamestring'sourcemaps.tar.gz'Archive name in bundle mode
deleteAfterUploadbooleanfalseDelete local .map files after a successful upload
ciOnlybooleanfalseOnly run in CI
verbosebooleantrue in CI, false locallyDetailed 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-data

https://app.sophonz.com/api/v1/web-sourcemaps serves the same endpoint.

Request fields

FieldDescription
fileThe source map. gzip-compressed content when contentEncoding=gzip
path, nameLogical path. Matched against the end of a stack frame's script URL
webVersionWeb version
appVersionWeb version when webVersion is absent
releaseWeb version when both are absent; unreleased when all three are
buildBuild ID
contentEncodinggzip when compressed
bundle, bundleFormat, fileCountBundle 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.
StatusCause
401Token missing, invalid, expired or revoked
400Not multipart, no file field, or an empty file
413File larger than 200MB
500The 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

  1. Sign in to https://app.sophonz.ai
  2. Open Settings
  3. Select the project and the app
  4. In Access tokens, enter a name and an expiry (never / 30 days / 90 days / 1 year) and create it
  5. 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.

  • CI
  • GITHUB_ACTIONS
  • GITLAB_CI
  • BUILDKITE
  • CIRCLECI
  • TRAVIS
  • BITBUCKET_BUILD_NUMBER