Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RavenModule
✓ import { RavenModule } from 'nest-raven';
✗ const { RavenModule } = require('nest-raven');
Use ES Module imports. CommonJS `require` is generally not idiomatic for modern NestJS applications, which are typically TypeScript and ESM-first.
RavenInterceptor
✓ import { RavenInterceptor } from 'nest-raven';
✗ import RavenInterceptor from 'nest-raven';
RavenInterceptor is a named export, not a default export.
APP_INTERCEPTOR
✓ import { APP_INTERCEPTOR } from '@nestjs/core';
While used with `nest-raven`, this is a core NestJS token for registering global interceptors, not directly from `nest-raven`.
This quickstart demonstrates how to initialize Sentry, integrate `RavenModule`, and use `RavenInterceptor` both locally on a route with filters (to ignore client errors) and globally for all controllers.
import { NestFactory } from '@nestjs/core';
import { Module, NestModule, UseInterceptors, Get, HttpException, Controller } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { RavenModule, RavenInterceptor } from 'nest-raven';
import * as Sentry from '@sentry/node';
// Initialize Sentry SDK early in your application lifecycle
Sentry.init({
dsn: process.env.SENTRY_DSN ?? 'YOUR_SENTRY_DSN_HERE',
tracesSampleRate: 1.0,
});
@Controller()
class AppController {
@UseInterceptors(new RavenInterceptor({
filters: [
{ type: HttpException, filter: (exception: HttpException) => exception.getStatus() < 500 }
],
// Example transformer to add custom data to Sentry scope
// transformer: (scope, context) => {
// const http = context.getType() === 'http' ? context.switchToHttp() : null;
// if (http) {
// const request = http.getRequest();
// scope.setExtra('customRequestData', { url: request.url, method: request.method });
// }
// return scope;
// }
}))
@Get('/error')
public async triggerError() {
throw new Error('This is a test error to be captured by Sentry!');
}
@Get('/client-error')
public async clientError() {
throw new new HttpException('This is a client error (400 level)', 400);
}
@Get('/server-error')
public async serverError() {
throw new new HttpException('This is a server error (500 level)', 500);
}
}
@Module({
imports: [RavenModule],
controllers: [AppController],
providers: [
{
provide: APP_INTERCEPTOR,
useValue: new RavenInterceptor(), // Global interceptor without filters
},
],
})
export class ApplicationModule {}
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
await app.listen(3000);
console.log('Application is running on: http://localhost:3000');
console.log('Visit /error, /client-error, /server-error to trigger errors.');
}
bootstrap();
Errors
Common errors & fixes
Error: Sentry SDK is not initialized, call Sentry.init() first.
The `@sentry/node` SDK was not initialized with `Sentry.init()` before the NestJS application started or before an error occurred.
fixAdd `Sentry.init({ dsn: process.env.SENTRY_DSN });` to your `main.ts` file at the top, before `NestFactory.create()`. Error: Can't resolve '@sentry/node' in 'node_modules/nest-raven/dist'
`@sentry/node` is a peer dependency of `nest-raven` but was not installed in your project.
fixInstall `@sentry/node`: `npm install @sentry/node` or `yarn add @sentry/node`.
TypeError: Cannot read properties of undefined (reading 'switchToHttp')
This error can occur in a custom `transformer` function if the `context` passed to it is not an HTTP context (e.g., from a GraphQL execution context) and the code assumes `switchToHttp()` is always available without checking.
fixSafely check the context type within your transformer: `const http = context.getType() === 'http' ? context.switchToHttp() : null;`
Audit
Dependencies
@nestjs/commonrequiredCore NestJS framework dependency, required for module and interceptor functionality.
@sentry/noderequiredThe underlying Sentry SDK for Node.js environments, essential for error reporting.
rxjsrequiredUsed internally by NestJS interceptors for reactive programming patterns.