Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

491
Vistas
Nest.js Testing Error: Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead

Here's the problem I have:

I am using my custom Logger in Nest.js:

export class ReportLogger extends ConsoleLogger {
  verbose(message: string) {
    console.log('【Verbose】Reporting', message);
    super.verbose.apply(this, arguments);
  }

  log(message: string) {
    console.log('【Log】Reporting', message);
    super.log.apply(this, arguments);
  }
}

And the log.interceptor.ts file:

export class LogInterceptor implements NestInterceptor {
  constructor(private reportLogger: ReportLogger) {
    this.reportLogger.setContext('LogInterceptor');
  }

  intercept(context: ExecutionContext, next: CallHandler) {
    const http = context.switchToHttp();
    const request = http.getRequest();

    const now = Date.now();
    return next
      .handle()
      .pipe(
        tap(() =>
          this.reportLogger.log(
            `${request.method} ${request.url} ${Date.now() - now}ms`,
          ),
        ),
      );
  }
}

And here's the main.ts file:

async function bootstrap() {
  const reportLogger = new ReportLogger();

  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    cors: {
      origin: ['http://localhost', 'http://localhost:3000'],
      credentials: true,
    },
    bufferLogs: true,
    logger: reportLogger,
  });

  app.useGlobalInterceptors(
    new LogInterceptor(reportLogger),
  );

  setupSwagger(app);

  await app.listen(4200);
}

When I run npm run start:dev to run the Nest App on dev, everything works fine. But when I run npm run test:e2e or npm run test on testing, it shows this error:

  Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead.

      10 |     const moduleFixture: TestingModule = await Test.createTestingModule({
      11 |       imports: [AppModule],
    > 12 |     }).compile();
         |        ^
      13 |
      14 |     app = moduleFixture.createNestApplication();
      15 |     await app.init();

I read the Nest.js doc again, and found the Logging breaking change in the docs. But the question is I have already made my ReportLogger extends ConsoleLogger, why this error shows again? And why it only shows in testing?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

even with "@nestjs/testing": "^8.0.7" this issue still occurs

class Logger implements LoggerService { ... }

await Test.createTestingModule({
  imports: [ApiModule],
})
  .setLogger(new Logger())
  .compile();

setting logger instance solves that error on my side

over 4 years ago · Santiago Trujillo Denunciar

0

I have faced the same problem after upgrading NestJS to version 8.

Later on, I found that package @nestjs/testing had previous version installed and was not upgraded to the latest version. The reason is, previous version of NestJS testing module is using the old Logger.

In order to fix this issue, you just need to upgrade the NestJS testing module.

Run this command for Latest version:

npm i @nestjs/testing@latest

OR specific version

npm i @nestjs/testing@8.0.6 // <--- Change the NestJS version here

After this, just build and run test cases again.

External Links:

  • NestJS Testing NPM
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda