{ "html": "
\n

Installation

\n

Raven.js should be installed via npm.

\n
$ npm install raven-js --save\n
\n
\n
\n\n\n
\n

Configuration

\n

Configuration depends on which module loader/packager you are using to build your Angular 2 application.

\n

Below are instructions for SystemJS, followed by instructions for Webpack, Angular CLI, and other module loaders/packagers.

\n
\n

SystemJS

\n

First, configure SystemJS to locate the Raven.js package:

\n
System.config({\n  packages: {\n    /* ... existing packages above ... */\n    'raven-js': {\n      main: 'dist/raven.js'\n    }\n  },\n  paths: {\n    /* ... existing paths above ... */\n    'raven-js': 'node_modules/raven-js'\n  }\n});\n
\n
\n

Then, in your main application file (where bootstrap is called, e.g. main.ts):

\n
import Raven from 'raven-js';\nimport { bootstrap } from 'angular2/platform/browser';\nimport { MainApp } from './app.component';\nimport { provide, ExceptionHandler } from 'angular2/core';\n\nRaven\n  .config('___PUBLIC_DSN___')\n  .install();\n\nclass RavenExceptionHandler {\n  call(err:any) {\n    Raven.captureException(err.originalException);\n  }\n}\n\nbootstrap(MainApp, [\n  provide(ExceptionHandler, {useClass: RavenExceptionHandler})\n]);\n
\n
\n

Once you’ve completed these two steps, you are done.

\n
\n
\n

Webpack, Angular CLI, and Other Module Loaders

\n

In Webpack, Angular CLI, and other module loaders/packagers, you may need to use the require keyword as\npart of your import statement:

\n
import Raven = require('raven-js');  // NOTE: "require" not "from"\nimport { bootstrap } from 'angular2/platform/browser';\nimport { MainApp } from './app.component';\nimport { provide, ExceptionHandler } from 'angular2/core';\n\nRaven\n  .config('___PUBLIC_DSN___')\n  .install();\n\nclass RavenExceptionHandler {\n  call(err:any) {\n    Raven.captureException(err.originalException);\n  }\n}\n\nbootstrap(MainApp, [\n  provide(ExceptionHandler, {useClass: RavenExceptionHandler})\n]);\n
\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/javascript/integrations/angular2/", "id": "javascript-angular2", "name": "Angular 2" }