Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!