socketio-jwt error in building typescript when importing library [Cannot find namespace 'SocketIO'.]

269 Views Asked by At

hello guys I am working on a nestjs@v9 that has a chat functionality and I want to be able to authorize the tokens sent by the user while creating the websocket

the app has a build script "build":"npm run remove-build && tsc -p tsconfig.build.json"

when running this script using yarn build it gives me the error

yarn run build stdout:
$ npm run remove-build && tsc -p tsconfig.build.json

> remove-build
> rm -rf dist

../../node_modules/socketio-jwt/types/index.d.ts(26,14): error TS2503: Cannot find namespace 'SocketIO'.
../../node_modules/socketio-jwt/types/index.d.ts(63,38): error TS2503: Cannot find namespace 'SocketIO'.

I found that if I remove this line // import { authorize } from 'socketio-jwt'; the error disappears but unfortunately I need to use this authorize method

so my question how can I solve this Issue.

[NOTE] i have this packages inside my package.json

    "socket.io": "^4.5.2",
    "socket.io-redis": "^6.1.1",
    "socketio-jwt": "^4.6.2",

the client should be connecting using this code

      const socket = io('http://localhost:1080', {
        transports: ['websocket'],
        query: {
          token: TOKEN,
        },
      });

the server should authorize the socket using

import { authorize } from 'socketio-jwt';

  public createIOServer(port: number, options?: ServerOptions): any {...
    const server = super.createIOServer(port, options);

    server.adapter(this.redisAdapter);
  server.use(
       authorize({
         decodedPropertyName: 'token',
         handshake: true,
        secret: secret,
      }) as any,
    );
0

There are 0 best solutions below