> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Upload source maps for Angular Canonical URL: https://posthog.com/docs/error-tracking/upload-source-maps/angular ## On this page - [AI wizard](#ai-wizard) - [Manual setup](#manual-setup) - [Install the PostHog CLI](#install-the-posthog-cli) - [Authenticate the PostHog CLI](#authenticate-the-posthog-cli) - [Output source maps for Angular](#output-source-maps-for-angular) - [Verify source map generation](#verify-source-map-generation) - [Inject source map](#inject-source-map) - [Verify source map injection](#verify-source-map-injection) - [Upload source map](#upload-source-map) - [Regenerate the service worker manifest](#regenerate-the-service-worker-manifest) - [Verify source map upload](#verify-source-map-upload) ## 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](https://posthog.com/blog/envoy-wizard-llm-agent.md) like Cursor and Bolt): `npx @posthog/wizard upload-source-maps` ## Manual setup 1. 1 ## Install the PostHog CLI Required Install `posthog-cli`: ### Npm ```bash npm install -g @posthog/cli ``` ### Curl ```bash curl -LsSf https://download.posthog.com/cli | sh ``` ### Homebrew ```bash brew install posthog/tap/posthog-cli ``` ### Cargo ```bash cargo install posthog-cli ``` 2. 2 ## Authenticate the PostHog CLI Required To authenticate the CLI, call the `login` command. This opens your browser where you select your organization, project, and API scopes to grant: ```bash posthog-cli login ``` If you are using the CLI in a CI/CD environment such as GitHub Actions, you can set environment variables to authenticate: | Environment Variable | Description | Source | | --- | --- | --- | | `POSTHOG_CLI_HOST` | The PostHog host to connect to \[default: https://us.posthog.com\] | [Project settings](https://app.posthog.com/settings/project#variables) | | `POSTHOG_CLI_PROJECT_ID` | PostHog project ID | [Project settings](https://app.posthog.com/settings/project#variables) | | `POSTHOG_CLI_API_KEY` | **Personal API key** with `error tracking write` and `organization read` scopes | [API key settings](https://app.posthog.com/settings/user-api-keys#variables) | You can also use the `--host` option instead of the `POSTHOG_CLI_HOST` environment variable to target a different PostHog instance or region. For EU users: ```bash posthog-cli --host https://eu.posthog.com [CMD] ``` 3. 3 ## Output source maps for Angular Required You can configure Angular to [generate source maps](https://angular.dev/reference/configs/workspace-config#source-map-configuration) by adding the following to your `angular.json` file: angular.json ```json "build": { "builder": "@angular-devkit/build-angular:application", "options": { "sourceMap": { "scripts": true, "styles": true, "hidden": true, "vendor": true } } } ``` Then, build your Angular application: ```bash 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//` directory. You should see a `.js.map` file for each JS bundle. 5. 4 ## 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. ```bash # Inject release and chunk metadata into sourcemaps posthog-cli sourcemap inject --directory ./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. 5 ## 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. ```bash # Upload injected sourcemaps to their release posthog-cli sourcemap upload --directory ./path/to/assets --release-name my-app --release-version 1.2.3 --build 42 ``` The CLI will create or reuse the [release](https://posthog.com/docs/error-tracking/releases.md) for the detected or supplied release name and version. The CLI will try to detect release name and version information, but you can set them explicitly with `--release-name` and `--release-version`. We recommend setting the release name, and letting the CLI 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 record a build number (e.g. `CFBundleVersion` on iOS, `versionCode` on Android) as release metadata. This is optional — when omitted, no build info is recorded. > **💡 Tip:** You can use `--delete-after` option to clean up sourcemaps after uploading them. #### 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 `posthog-cli sourcemap inject`, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces. 8. 6 ## 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`. `posthog-cli sourcemap 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`](https://angular.dev/ecosystem/service-workers/config) tool that ships with `@angular/service-worker`: ```bash ng build --configuration production posthog-cli sourcemap process --directory ./dist//browser npx ngsw-config ./dist//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](https://app.posthog.com/error_tracking/configuration#selectedSetting=error-tracking-symbol-sets)