esbuild
Upload your source maps with the Sentry esbuild Plugin.
This guide assumes you're using a Sentry SDK version 7.47.0
or higher. If you're on an older version and you want to upload source maps, we recommend upgrading your SDK to the newest version.
The Sentry esbuild plugin doesn't fully support esbuild configurations, with splitting: true
. If you rely on code splitting, use the esbuild plugin with legacy source maps upload or Sentry CLI to upload source maps instead.
You can use the Sentry esbuild plugin to automatically create releases and upload source maps to Sentry when bundling your app.
The easiest way to configure source map uploading with esbuild is by using the Sentry Wizard:
npx @sentry/wizard@latest -i sourcemaps
The wizard will guide you through the following steps:
- Logging into Sentry and selecting a project
- Installing the necessary Sentry packages
- Configuring your build tool to generate and upload source maps
- Configuring your CI to upload source maps
If you want to configure source map uploading with esbuild manually, follow the steps below.
Install the Sentry esbuild plugin:
npm install @sentry/esbuild-plugin --save-dev
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.
Learn more about configuring the plugin in our Sentry esbuild Plugin documentation.
.env.sentry-build-plugin
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
Example:
esbuild.config.js
const { sentryEsbuildPlugin } = require("@sentry/esbuild-plugin");
require("esbuild").build({
sourcemap: true, // Source map generation must be turned on
plugins: [
// Put the Sentry esbuild plugin after all other plugins
sentryEsbuildPlugin({
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 Esbuild Plugin's sourcemaps.filesToDeleteAfterUpload
option to delete source maps after they've been uploaded to Sentry.
The Sentry esbuild plugin doesn't upload source maps in watch-mode/development-mode. We recommend running a production build to test your configuration.
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").