---
title: "Nx CLI"
description: "Upload your source maps using the Nx CLI and the Sentry webpack plugin."
url: https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx/
---

# Nx CLI for Angular

If you're using [`@nx/angular`](https://nx.dev/packages/angular), you can use the Nx CLI together with one of our bundler plugins (such as Webpack or esbuild) to automatically upload source maps to Sentry when building your app (with `nx build`, for example).

Due to `@nx/angular`'s architecture, you'll first need to configure an executor that allows registering bundler plugins. In the end, you'll be able to automatically upload source maps whenever you're creating a production build of your app.

Configure your app to upload source maps in three steps.

## [1. Configure `project.json`](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#1-configure-projectjson)

Before you register the Sentry bundler plugin, first ensure that you can register plugins (such as webpack or esbuild plugins) with your current executor (or Angular builder). Typically, this is possible if you have access to a `webpack.config.js` or a similar configuration file. If this already is the case, skip to [step 2](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#2-register-the-sentry-webpack-plugin).

If you can't register a plugin, you'll need to change the executor in your `project.json` to a custom executor that allows you to register it (such as [`@nx/angular:webpack-browser`](https://nx.dev/nx-api/angular/executors/webpack-browser) or [`@nx/angular:browser-esbuild`](https://nx.dev/nx-api/angular/executors/browser-esbuild)).

Check out the example below: in your `project.json`, replace the default executor (`@angular-devkit/build-angular:browser`) with `@nx/angular:webpack-browser`:

```javascript
{
  "targets": {
    "build": {
      "executor": "@nx/angular:webpack-browser",
      "options": {
        "customWebpackConfig": {
          "path": "./webpack.config.js" // path to your webpack.config.js
        },
        "sourceMap": { // enable source maps generation
            "scripts": true,
         }
        // ... other options
      },
      // ... other options
    }
  }
}
```

## [2. Register the Sentry Bundler Plugin](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#2-register-the-sentry-bundler-plugin)

This guide assumes you are using a Sentry SDK on version `7.47.0` or higher.

If you are on an older version and you want to upload source maps we recommend upgrading your SDK to the newest version.

To upload source maps you have to configure an [Organization Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/).

Alternatively, you can also use a [Personal Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/account/api/auth-tokens/), with the "Project: Read & Write" and "Release: Admin" permissions.

Auth tokens can be passed to the plugin explicitly with the `authToken` option, with a `SENTRY_AUTH_TOKEN` environment variable, or with an `.env.sentry-build-plugin` file (don't forget to add it to your `.gitignore` file, as this is sensitive data) in the working directory when building your project. We recommend you add the auth token to your CI/CD environment as an environment variable.

```bash
SENTRY_AUTH_TOKEN=<your-sentry-auth-token>
```

### [Webpack](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#webpack)

Install the Sentry Webpack plugin:

```shell
npm install @sentry/bundler-plugins --save-dev
```

*Other available variations of the above snippet: yarn, pnpm*

Register the Sentry webpack plugin in your `webpack.config.js`:

```javascript
const { sentryWebpackPlugin } = require("@sentry/bundler-plugins/webpack");

module.exports = {
  // ... other config above ...

  plugins: [
    sentryWebpackPlugin({
      org: "<your-org-slug>",
      project: "<your-project-slug>",
      authToken: process.env.SENTRY_AUTH_TOKEN,
      sourcemaps: {
        delete: true,
      },
    }),
  ],
};
```

Angular turns on the source maps, so the plugin keeps them in the build output by default. `sourcemaps.delete: true` removes them after the upload, so your users can't download them.

Learn more about configuring the plugin in our [Sentry webpack plugin documentation](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/bundler-plugin-options.md).

### [esbuild](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#esbuild)

Install the Sentry esbuild plugin:

```shell
npm install @sentry/bundler-plugins --save-dev
```

*Other available variations of the above snippet: yarn, pnpm*

Then, follow the [official Nx documentation](https://nx.dev/nx-api/angular/executors/browser-esbuild#examples) to register the Sentry esbuild plugin (`@sentry/bundler-plugins/esbuild`) in your `project.json` file. For example:

```json
{
  "targets": {
    "build": {
      "executor": "@nx/angular:browser-esbuild",
      "options": {
        "plugins": [
          {
            "path": "@sentry/bundler-plugins/esbuild",
            "options": {
              "org": "<your-org-slug>",
              "project": "<your-project-slug>",
              "authToken": "___SENTRY_AUTH_TOKEN___",
              "sourcemaps": {
                "delete": true
              }
            }
          }
        ]
      }
    }
  }
}
```

Angular turns on the source maps, so the plugin keeps them in the build output by default. `sourcemaps.delete: true` removes them after the upload, so your users can't download them.

## [3. Upload](https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/uploading/angular-nx.md#3-upload)

To upload the source maps, build your Angular application:

```bash
nx build
```

The Sentry webpack plugin doesn't upload source maps in watch-mode/development-mode. We recommend running a production build to test your implementation.

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
