Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda