Node.js and Electron source maps

Using our source map library you can upload source maps to unminify stack traces and get human-readable method names, files, and line numbers.

Installation

@bugsnag/source-maps provides a CLI and a JavaScript library that can be used to upload your application’s source maps.

Install it globally on your system:

npm install --global @bugsnag/source-maps
# or
yarn global add @bugsnag/source-maps

Or locally inside your project:

npm install --save-dev @bugsnag/source-maps
# or
yarn add --dev @bugsnag/source-maps

Usage

The library can be used via the command line:

# CLI
bugsnag-source-maps upload-node <opts>

Or as a JavaScript API:

const { node } = require('@bugsnag/source-maps')

interface node  {
  async function uploadOne (UploadSingleOpts): Promise<void>
  async function uploadMultiple (UploadMultipleOpts): Promise<void>
}

Electron

To apply source maps for Electron apps, upload your main and renderer bundles using the Node.js options.

If you publish renderer JS updates without releasing a new version of your app, use the codeBundleId option to identify the bundle to BugSnag for matching source maps. This should be set to a matching value in notifier configuration.

If you’re using Electron Forge with the Webpack plugin you can use BugSnag’s Webpack plugin. See the Webpack integration docs.

Examples

You can upload a single source map and bundle pair:

bugsnag-source-maps upload-node \
  --api-key YOUR_API_KEY_HERE \
  --app-version 1.2.3 \
  --source-map dist/index.js.map \
  --bundle dist/index.js

Or when your build doesn’t combine the output into a single bundle, but creates a generated file and source map for every input file (for instance, the Babel or TypeScript compiler when not used in conjunction with a bundler) use the directory mode:

bugsnag-source-maps upload-node \
  --api-key YOUR_API_KEY_HERE \
  --app-version 1.2.3 \
  --directory dist

Option reference

The full set of options for @bugsnag/source-maps.

Property (CLI, JS API) Type Description
--api-key,
apiKey
string your project’s API key [required]
--app-version,
appVersion
string the version of the application you are building (this should match the appVersion configured in your notifier).
--detect-app-version,
detectAppVersion
boolean detect the app version from the package.json file
--code-bundle-id,
codeBundleId
string (Electron only) uniquely identify the bundle if published separately to your app
--endpoint,
endpoint
string customize the endpoint for BugSnag On-Premise
--idle-timeout,
idleTimeout
number idle timeout for HTTP requests in minutes (see the Node request.setTimeout docs)
logger
(JS only)
Object provide a custom logger (must match the internal Logger interface)
--overwrite,
overwrite
boolean whether to replace existing source maps uploaded with the same version
--project-root,
projectRoot
string the top level directory of your project
requestOpts
(JS only)
RequestOptions supply options that should be passed to http.request(), for example if you need to provide an agent to send via a proxy
--quiet (CLI only) boolean less verbose logging
Singe upload options
--source-map,
sourceMap
string the path to the source map [required]
--bundle,
bundle
string the path to the bundle [required]
Multiple upload options
--directory,
directory
string the directory to start searching for source maps in, relative to the project root [required]