saj*_*jan 5 websocket node.js nestjs
我在我的 nestjs 应用程序中看到这个错误
(node:16561) UnhandledPromiseRejectionWarning: TypeError: this.contextUtils.getContextFactory 不是 WsContextCreator.getMetadata 的函数 (/Users/sajankumarvijayan/Documents/projects/review.io/node_modules/@nestjs/websockets/context/ws-context-creator .js:73:50) 在 WsContextCreator.create (/Users/sajankumarvijayan/Documents/projects/review.io/node_modules/@nestjs/websockets/context/ws-context-creator.js:28:68)
这是我的示例代码:
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');
}
}
Run Code Online (Sandbox Code Playgroud)
如果我删除 @SubscribeMessage 注释,错误就会消失。我认为这个异常没有被处理,而是在寻找一些答案并帮助解决这个问题。谢谢你。
它发生在我身上,在我的情况下是版本问题,我使用的是@nestjs/common和@nestjs/core包的 6.x 版。
在我对这些库进行重大升级后,它得到了修复。由于我没有任何版本限制,因此我执行了完整的主要版本升级。遵循npm 的说明
一步
npm i -g npm-check-updates && ncu -u && npm i
Run Code Online (Sandbox Code Playgroud)
或者拆开...
如果您还没有安装检查更新
npm install -g npm-check-updates
Run Code Online (Sandbox Code Playgroud)
给你名单
ncu -u
Run Code Online (Sandbox Code Playgroud)
安装
npm install
Run Code Online (Sandbox Code Playgroud)
这也将更新您的package.json文件
归档时间: |
|
查看次数: |
3021 次 |
最近记录: |