Upload source maps for React

AI wizard

Set up source map uploading automatically with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):

Manual setup

  1. Install the PostHog CLI

    Required

    Install hog, PostHog's CLI:

    curl -fsSL https://posthog.com/install.sh | sh

    In GitHub Actions, install hog with the PostHog/setup-hog action:

    YAML
    - uses: PostHog/setup-hog@v1
  2. Authenticate the PostHog CLI

    Required

    Log in to PostHog. This opens your browser, where you approve the login:

    Terminal
    hog auth login

    If posthog-cli is already logged in on this machine, import that login instead:

    Terminal
    hog auth migrate

    hog reads only the HOG_* names. The PostHog build plugins and upload scripts still pass the old POSTHOG_CLI_* names to hog for now, with a warning for each one. A hog command you run yourself needs the HOG_* names. The migration guide lists each rename.

  3. Output source maps for your framework

    Required
    If you're using React with Vite, you can enable source maps in your `vite.config.js` file.
    JavaScript
    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    export default defineConfig({
    plugins: [react()],
    build: {
    sourcemap: true,
    }
    })

    If you're using another build tool like webpack or Rollup, consult the documentation for your build tool to enable source maps.

  4. Inject source map

    Required

    Once you've built your application and have bundled assets, inject the context required by PostHog to associate the maps with the served code.

    Terminal
    # Inject release and chunk metadata into sourcemaps
    hog error-tracking inject ./path/to/assets

  5. Verify source map injection

    Checkpoint
    Confirm source map comments are present

    Confirm that the served files are injected with the correct source map comment in production in dev tools.

    JavaScript
    //# chunkId=0197e6db-9a73-7b91-9e80-4e1b7158db5c
  6. Upload source map

    Required

    You will then need to upload the modified assets to PostHog.

    Terminal
    # Upload injected sourcemaps to their release
    hog error-tracking upload ./path/to/assets --release-name my-app --release-version 1.2.3

    hog creates or reuses the release for the detected or supplied release name and version. hog tries to detect the release name and version from Git and your CI provider, but you can set them explicitly with --release-name and --release-version. We recommend setting the release name, and letting hog detect the version, if your project is continuously deployed (the version will be the git commit hash at build time).

    You can also pass --build to add a build number (e.g. CFBundleVersion on iOS, versionCode on Android) to the release version, as <version>+<build>. This is optional.

    💡 Tip: You can use the --delete-after option to clean up sourcemaps after uploading them. To inject and upload in one command, use hog error-tracking process ./path/to/assets.

    Serve injected assets

    You must serve the injected assets in deployed production app. The injected metadata is used during error capture to identify the correct source map to use. We suggest you upload source maps right after your production build in CI.

    If you serve a copy of the bundled assets as they were prior to running hog error-tracking inject, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces.

  7. Verify source maps upload

    Checkpoint
    Confirm that source maps are successfully uploaded to PostHog.Check symbol sets in PostHog

Still have questions?

Was this page useful?