Importing or Requiring Rollbar

JavaScript developers often working with Typescript, a variant of ECMAScript to help make their code more readable, efficient and maintainable. This guide is to help you understand how you can install Rollbar if you were to use either Typescript or ECMAScript (ES5, ES6, ES7, ES8, ES9).


Correct import syntax depends on the project tsconfig compilerOptions.module value.

module: ‘commonjs’

For Node.js and for projects that target es5 compiled code, module: ‘commonjs’ is the default and most common module setting, as it will produce compatible module loading for the target.

Rollbar’s Typescript export uses export = syntax and its import statement should use import = require() syntax. Note that this is specific to Typescript and isn’t valid syntax in other environments.

import Rollbar = require('rollbar')

See: [] (

module: ‘es2015’ (or ‘es6’, ‘esnext’)

For targets higher than es5, the most common module settings are ‘es2015’, ‘es6’, or ‘esnext’. These won’t allow the above import = require() syntax. Instead, use es6 import syntax:

import Rollbar from 'rollbar';


The es6 import syntax requires setting esModuleInterop in the tsconfig compilerOptions.

See: [] (

Namespace import syntax (not recommended)

Namespace import syntax will work in some project configurations and not in others:

import * as Rollbar from ‘rollbar’ // not recommended

For example, this works in Angular through version 8, but will no longer work in Angular 9. This is not a recommended syntax.


For versions, ES6, ES7, ES8, and ES9 use the following code example to import Rollbar.

// ES6, ES7, ES8, ES9
import Rollbar from "rollbar";

If you are using ES5, import Rollbar using this sample code snippet.

// ES5
var Rollbar = require('rollbar');