This directory contains examples demonstrating various ways to integrate Rollbar.js into different JavaScript environments and frameworks.
The following table shows all supported integration methods across different platforms:
| Environment | Script Tag | CommonJS | ESM Import | TypeScript | AMD |
|---|---|---|---|---|---|
| Browser | ✅ script.html ✅ snippet.html |
— | ✅ via bundler | ✅ via bundler | ✅ requirejs/ |
| Node.js | — | ✅ require |
✅ import |
✅ | — |
| React Native | — | ✅ | ✅ | ✅ | — |
| React | ✅ | ✅ react/ | ✅ | ✅ | — |
| Angular | — | — | ✅ angular/ | ✅ | — |
| Vue.js | ✅ | ✅ | ✅ vuejs3/ | ✅ | — |
| Next.js | — | ✅ SSR/Client | ✅ SSR/Client | ✅ | — |
| Browser Extension | ✅ v2, v3 | — | ✅ | ✅ | — |
First, sign up for a Rollbar account if you haven't already. Each example includes its own README with specific setup instructions.
Common patterns:
For the recommended snippet-based installation with automatic error capture and telemetry, see our Browser JS – Quick Start documentation.
const Rollbar = require('rollbar');
const rollbar = new Rollbar({
accessToken: 'POST_SERVER_ITEM_ACCESS_TOKEN',
captureUncaught: true,
captureUnhandledRejections: true,
payload: { code_version: '1.0.0' },
});import Rollbar from 'rollbar';
const rollbar = new Rollbar({
accessToken: 'POST_SERVER_ITEM_ACCESS_TOKEN',
environment: 'production',
});- angular/ - Angular 18+ with TypeScript and error handlers
- react/ - React with error boundaries
- vuejs3/ - Vue.js 3 with Vite
- browserify/ - Browserify bundler integration
- webpack/ - Webpack bundler configuration
- requirejs/ - AMD/RequireJS loader
- universal-browser/ - Isomorphic JavaScript (browser)
- universal-node/ - Isomorphic JavaScript (Node.js)
- browser_extension_v2/ - Chrome extension (Manifest V2)
- browser_extension_v3/ - Chrome extension (Manifest V3)
- no-conflict/ - Using Rollbar with noConflict mode
- snippet.html - Async snippet integration
- script.html - Direct script tag
- test.html - Test page
- itemsPerMinute.html - Rate limiting demo
- include_custom_object.html - Custom data example
To test these examples with your local Rollbar.js build:
-
Build the library:
npm run build
-
For Node.js examples:
cd examples/universal-node npm install npm start -
For browser examples, start a local server:
python3 -m http.server 8000 # Visit http://localhost:8000/examples/
Rollbar.js uses conditional exports to provide the right module format for each environment:
When you use require('rollbar') or import Rollbar from 'rollbar', you automatically get:
- Node.js:
import→ ES module (src/server/rollbar.js)require()→ CommonJS wrapper (src/server/rollbar.cjs)
- Browsers/Bundlers:
import→ ES module (src/browser/rollbar.js)require()→ UMD bundle (dist/rollbar.umd.min.js)
- TypeScript: Type definitions from
index.d.ts
rollbar/src/server/rollbar.js- Server-side sourcerollbar/src/browser/rollbar.js- Browser-side sourcerollbar/src/react-native/rollbar.js- React Native source
rollbar/dist/rollbar.umd.js- Universal (CommonJS/AMD/global)rollbar/dist/rollbar.umd.min.js- Universal minifiedrollbar/dist/rollbar.js- Vanilla (script tag only)rollbar/dist/rollbar.min.js- Vanilla minifiedrollbar/dist/rollbar.snippet.js- Async snippet loaderrollbar/dist/rollbar.named-amd.js- AMD/RequireJS