Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

407
Vistas
socket.io Typescript fails to create a server, "This expression is not callable"

I have the following code(server):

import express from "express";
import socketio from "socket.io";
import http from "http";

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

server.listen(process.env.port || 3000, () => {
  console.log(`App running on port ${process.env.port || 3000}`);
});

But i get an error on const io = socketio(server);, It states:

This expression is not callable. Type 'typeof import("SOME_PATH/node_modules/socket.io/dist/index")' has no call signatures

What exactly is the problem here?

package.json:

 "devDependencies": {
    "@types/express": "^4.17.11",
    "@types/node": "^14.14.27",
    "@types/socket.io": "^2.1.13",
    "nodemon": "^2.0.7",
    "ts-node": "^9.1.1"
  },
  "dependencies": {
    "express": "^4.17.1",
    "socket.io": "^3.1.1",
    "typescript": "^4.1.5"
  }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The api changed in version 3. This issue here has some discussion.

The new equivalent of your example would be

import express from "express";
import { Server } from "socket.io";
import http from "http";

const app = express();
const server = http.createServer(app);
const io = new Server(server);

server.listen(process.env.port || 3000, () => {
  console.log(`App running on port ${process.env.port || 3000}`);
});

As a side note, socket.io was rewritten in typescript, so you no longer need to have @types/socket.io.

over 4 years ago · Santiago Trujillo Denunciar

0

Not sure about that, but the problem seems to be in the way socket.io describe its own default export.

I solved this by casting it as any

    import io from 'socket.io';
    const server = (io as any)(http);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda