Upload source maps for JavaScript builds

To get unminified stack traces for JavaScript code, source maps must be generated and uploaded to BugSnag.

For installation instructions for the BugSnag CLI, please see our Installation guide.

Overview

The js command uploads minified JavaScript and the associated source map files to the JavaScript source map API.

In order to unminify stacktraces, the source maps must contain the original source code so it can be presented in your BugSnag dashboard. This is usually generated by your build tool by default, in the sourcesContent field of the source map. In cases where the source isn’t found in the source map, this command attempts to read the lines of source code from the local filesystem and add it to the source map before uploading it. If this fails, the command will report and error as without the code, the stacktraces cannot be unminified.

In addition to the source maps, the command extracts version information from your package.json file, if found. This value can be overridden by the command line option.

Example usage

The simplest way to run the command is from the root directory of your JavaScript project, specifying your project API key and the remote URL of your minified files:

$ bugsnag-cli upload js --api-key=YOUR_API_KEY --base-url="https://example.com/js"

Or by providing a specific minified file and associated source map to upload, along with with the remote URL of the minified file:

$ bugsnag-cli upload js \
    --api-key=YOUR_API_KEY \
    --bundle dist/main.min.js \
    --source-map dist/main.js.map \
    --bundle-url "https://example.com/js/main.min.js"

You can find your API key in Project Settings from your BugSnag dashboard.

The command requires either --base-url or --bundle-url to be set to the URL where the minified JavaScript is served. This allows the paths reported in stacktraces to be resolved to the uploaded sourcemap(s).

Available options

API key (--api-key)

The BugSnag API key for the application.

You can find your API key in Project Settings from your BugSnag dashboard.

Base URL (--base-url)

For directory-based uploads, the URL of the base directory for the minified JavaScript files that the source maps relate to. The relative path is appended onto this for each file. Asterisks can be used as a wildcard.

Bundle (--bundle)

Path to the minified JavaScript file that the source map relates to. If this is not provided then the file will be obtained when an error event is received.

Bundle URL (--bundle-url)

For single file uploads, the URL of the minified JavaScript file that the source map relates to. Asterisks can be used as a wildcard.

Dry run (--dry-run)

Performs a dry-run of the command without sending any information to BugSnag.

Fail on upload error (--fail-on-upload-error)

Stops the upload when a file fails to upload successfully.

Log level (--log-level)

Sets the level of logging to debug, info, warn or fatal.

Default: info.

Overwrite (--overwrite)

Whether to ignore and overwrite existing uploads with same identifier, rather than failing if a matching file exists.

Port (--port)

The port number for the BugSnag upload server.

Default: 443.

Project root (--project-root)

The path to strip from the beginning of source file names referenced in stacktraces on the BugSnag dashboard.

Default: the root directory if the command has detected one, otherwise it’s empty.

Retries (--retries)

The number of retry attempts before failing an upload request.

Default: 0.

Source map (--source-map)

Path to the source map file. This usually has the .min.js extension.

Timeout (--timeout)

The number of seconds to wait before failing an upload request.

Default: 300.

Upload API root URL (--upload-api-root-url)

The upload server hostname, optionally containing port number.

For use in BugSnag On-premise configurations. The command will append the appropriate path to access the correct upload endpoint.

Default: https://upload.bugsnag.com.

Verbose (--verbose)

Sets the level of the logging to its highest.

This is the equivalent of setting the log level to debug.

Version name (--version-name)

The version of the app that the source map applies to. Defaults to the version in the package.json file (if found).