Nx CLI
Upload your source maps using the Nx CLI and the Sentry webpack plugin.
If you're using @nx/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.
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.
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
or @nx/angular: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
:
project.json
{
"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
}
}
}
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 Auth Token.
Alternatively, you can also use a User Auth Token, 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.
.env.sentry-build-plugin
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
Install the Sentry Webpack plugin:
npm install @sentry/webpack-plugin --save-dev
Register the Sentry webpack plugin in your webpack.config.js
:
webpack.config.js
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
module.exports = {
// ... other config above ...
devtool: "source-map", // Source map generation must be turned on
plugins: [
sentryWebpackPlugin({
org: "example-org",
project: "example-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
}),
],
};
Generating sourcemaps may expose them to the public, potentially causing your source code to be leaked. You can prevent this by configuring your server to deny access to .js.map
files, or by using Sentry Webpack Plugin's sourcemaps.filesToDeleteAfterUpload
option to delete source maps after they've been uploaded to Sentry.
Learn more about configuring the plugin in our Sentry webpack plugin documentation.
Install the Sentry esbuild plugin:
npm install @sentry/esbuild-plugin --save-dev
Then, follow the official Nx documentation to register the Sentry esbuild plugin (@sentry/esbuild-plugin
) in your project.json
file. For example:
project.json
{
"targets": {
"build": {
"executor": "@nx/angular:browser-esbuild",
"options": {
"plugins": [
{
"path": "@sentry/esbuild-plugin",
"options": {
"org": "example-org",
"project": "example-project",
"authToken": ""
}
}
]
}
}
}
}
Generating sourcemaps may expose them to the public, potentially causing your source code to be leaked. You can prevent this by configuring your server to deny access to .js.map
files, or by using Sentry Esbuild Plugin's sourcemaps.filesToDeleteAfterUpload
option to delete source maps after they've been uploaded to Sentry.
To upload the source maps, build your Angular application:
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.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").