简体   繁体   English

NestJs WebSockets UnhandledPromiseRejectionWarning

[英]NestJs websockets UnhandledPromiseRejectionWarning

I'm trying to add a 'events' module to my application for using websockets, but when I add the module I get the following error: 我正在尝试向应用程序中添加一个“事件”模块以使用websockets,但是当我添加该模块时,出现以下错误:

(node:59905) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request mapping properties not defined in the @RequestMapping() annotation!
(node:59905) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

All the other modules are loaded and mapped successfully and it only happens when I add the EventsModule 所有其他模块均已成功加载和映射,并且仅当我添加EventsModule时才会发生

so here's the code that I have: 所以这是我的代码:

app.module.ts app.module.ts

@Module({
    modules: [AuthModule, DatabaseModule, UsersModule, TimespansModule, LogsModule, EntitiesModule, EventsModule]
})

events.module.ts events.module.ts

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';
@Module({
    controllers: [EventsComponent]
})
export class EventsModule {}

events.component.ts events.component.ts

import {WebSocketGateway, SubscribeMessage, OnGatewayConnection} from '@nestjs/websockets';

@WebSocketGateway({namespace: 'events'})
export class EventsComponent implements OnGatewayConnection {
    handleConnection(client: any) {
        console.log('client connected');
    }

    @SubscribeMessage('stream-received')
    onStream(client, data) {
        console.log('stream received');
    }
}

I can't really see what's going wrong here, also the error message doesn't help me a lot. 我真的看不到这里出了什么问题,错误消息也没有太大帮助。

found the issue in events.module.ts 在events.module.ts中发现了问题

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';    
@Module({
    controllers: [EventsComponent]
})
export class EventsModule {}

had to change controllers => components 必须更换控制器=>组件

import {EventsComponent} from './events.component';
import {Module} from '@nestjs/common';    
@Module({
    components: [EventsComponent]
})
export class EventsModule {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 NestJs 和 ReactJS 中使用 websocket - Use websockets in NestJs and ReactJS Nestjs Swagger UnhandledPromiseRejectionWarning:TypeError:无法解构“ undefined”或“ null”的属性“ prototype” - Nestjs Swagger UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property `prototype` of 'undefined' or 'null' 如何在 NestJS 的 azure 服务总线客户端中将 Transport 或 websockets 添加为“AmqpWebSockets”? - How to add Transport or websockets as “AmqpWebSockets” in azure service bus client in nestJS? NodeJS:未处理的承诺拒绝警告 - NodeJS:UnhandledPromiseRejectionWarning UnhandledPromiseRejectionWarning: MongooseServerSelectionError - UnhandledPromiseRejectionWarning: MongooseServerSelectionError 量角器中未处理的承诺拒绝警告 - UnhandledPromiseRejectionWarning in protractor UnhandledPromiseRejectionWarning:ValidationError - UnhandledPromiseRejectionWarning: ValidationError 异步UnhandledPromiseRejection警告 - Async UnhandledPromiseRejectionWarning Puppeteer UnhandledPromiseRejectionWarning - Puppeteer UnhandledPromiseRejectionWarning 注册,UnhandledPromiseRejectionWarning,UnhandledPromiseRejectionWarning:QueryResultError:0,DeprecationWarning - Signup, UnhandledPromiseRejectionWarning, UnhandledPromiseRejectionWarning: QueryResultError: 0, DeprecationWarning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM