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

211
Vistas
socket.io client with TypeScript

I am trying to use TypeScript with socket.io in my client:

import { Manager, Socket} from "socket.io-client";
import {DefaultEventsMap} from "@socket.io/component-emitter";

export class SocketIoService {
    private socket: Socket<DefaultEventsMap, DefaultEventsMap>

    constructor() {
        const manager = new Manager("http://localhost:3000");
        this.socket = manager.socket("/");
    }

    public connect() {
        this.socket.emit("hello");
        this.socket.on("noArg", () => {
            // ...
        });

        this.socket.on("basicEmit", (a, b, c) => {
            // a is inferred as number, b as string and c as buffer
            console.log(a + b + c);
        });
    }
}

The problem is when I start my server I get the following error:

The requested module './../../../parseuri/index.js' does not provide an export named 'default'

What have I done wrong?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

  • Update the client-side
  • Check updated documentation was updated here: https://socket.io/docs/v3/server-initialization/#Syntax

Server:

import { Server } from "socket.io";

const io = new Server(httpServer);

Client:

import { Manager } from "socket.io-client";

const manager = new Manager("http://localhost:3000");
const socket = manager.socket("/");
about 4 years ago · Juan Pablo Isaza Denunciar

0

(this should have been a comment but I do not have enough rep to comment)

The error signifies that you are trying to default import from a module which has named exports.

Can you attach the stacktrace of the error?

I am interested in the module which triggers the import to './../../../parseuri/index.js'.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I'm not entirely sure how the error is related to this specific code. I just created an empty folder, added your code in, and with an empty tsconfig.json was able to compile. Here's the compiled code:

"use strict";
exports.__esModule = true;
exports.SocketIoService = void 0;
var socket_io_client_1 = require("socket.io-client");
var SocketIoService = /** @class */ (function () {
    function SocketIoService() {
        var manager = new socket_io_client_1.Manager("http://localhost:3000");
        this.socket = manager.socket("/");
    }
    SocketIoService.prototype.connect = function () {
        this.socket.emit("hello");
        this.socket.on("noArg", function () {
            // ...
        });
        this.socket.on("basicEmit", function (a, b, c) {
            // a is inferred as number, b as string and c as buffer
            console.log(a + b + c);
        });
    };
    return SocketIoService;
}());
exports.SocketIoService = SocketIoService;

I'd suggest doing:

$ rm -rf node_modules
$ npm i

And trying again.

about 4 years ago · Juan Pablo Isaza 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