Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nestjs @SubscribeMessage UnhandledPromiseRejectionWarning: TypeError: this.contextUtils.getContextFactory is not a function

I am seeing this error in my nestjs application

(node:16561) UnhandledPromiseRejectionWarning: TypeError: this.contextUtils.getContextFactory is not a function at WsContextCreator.getMetadata (/Users/sajankumarvijayan/Documents/projects/review.io/node_modules/@nestjs/websockets/context/ws-context-creator.js:73:50) at WsContextCreator.create (/Users/sajankumarvijayan/Documents/projects/review.io/node_modules/@nestjs/websockets/context/ws-context-creator.js:28:68)

Here is my example code:

import {
   SubscribeMessage,
   WebSocketGateway,
   WebSocketServer,
} from '@nestjs/websockets';
import { Server } from 'ws';

@WebSocketGateway()
export class SocketGateway {
  @WebSocketServer()
  server: Server;

  @SubscribeMessage('event')
  onEvent(client: any, data: any): void {
    this.server.emit('update');
  }
}

If i remove the @SubscribeMessage annotation the error is gone. I think this exception is not handled but looking for some answers and help to fix this. Thank you.

like image 754
sajan Avatar asked Mar 15 '20 16:03

sajan


1 Answers

I faced the same issue and it disappeared after I upgraded @nestjs/core and @nestjs/common to 7.x.x versions

like image 144
Željko Šević Avatar answered Nov 15 '22 04:11

Željko Šević