Upload source maps for Angular

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 Angular

    Required

    You can configure Angular to generate source maps by adding the following to your angular.json file:

    angular.json
    "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
    "sourceMap": {
    "scripts": true,
    "styles": true,
    "hidden": true,
    "vendor": true
    }
    }
    }

    Then, build your Angular application:

    Terminal
    ng build --configuration production
  4. Verify source map generation

    Checkpoint
    Confirm source maps are generated

    Confirm that the source maps are generated in the dist/<your-app-name>/ directory. You should see a .js.map file for each JS bundle.

  5. Inject source map

    Required
    Your goal in this step: Add metadata to associate maps with your code.

    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

  6. 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:

    You should see a comment like this in your minified JS files, for example main-IX6K2QJM.js:

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

    Required
    Your goal in this step: Send the processed source maps to PostHog.

    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.

  8. Regenerate the service worker manifest

    Required
    Your goal in this step: Keep the Angular service worker's asset hashes in sync with the injected files.
    Only needed if you use the Angular service worker

    Skip this step if your app doesn't use @angular/service-worker.

    ng build writes a SHA-1 hash of every bundle into ngsw.json. hog error-tracking inject rewrites those bundles afterwards, so the recorded hashes no longer match the files. When the service worker detects the mismatch, it rejects the new version and keeps serving the previously cached app, so your deploys silently stop reaching users.

    Fix this by regenerating ngsw.json after processing, using the ngsw-config tool that ships with @angular/service-worker:

    Terminal
    ng build --configuration production
    hog error-tracking process ./dist/<your-app-name>/browser
    npx ngsw-config ./dist/<your-app-name>/browser ./ngsw-config.json /

    Run ngsw-config as the last command that touches the build output. --delete-after also rewrites your bundles when it strips the source map comments, so it must run before ngsw-config too. The last argument is your app's base href (usually /).

  9. Verify source map upload

    Checkpoint
    Confirm source maps are successfully uploaded

    Before proceeding, confirm that source maps are successfully uploaded to PostHog.

    Check symbol sets in PostHog

Still have questions?

Was this page useful?