Correct import syntax depends on the project tsconfig
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')
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
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');
Updated about a month ago