HowtoimportSocket.iousingimport-Nodejs

Not sure why I am getting the error. When I try to do the same thing by using request it works fine.

import express from 'express';
import { createServer } from 'http';
import * as io from 'socket.io';

const app = express();
const server = createServer(app);
const socketio = io(server);

Error

const socketio = io(server);
                 ^

TypeError: io is not a function

回答

你应该试试这个

import { Server } from "socket.io";
const httpServer = createServer();
const io = new Server(httpServer, {
  // ...
});

在这里查看Socket.io 初始化


以上是HowtoimportSocket.iousingimport-Nodejs的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>