Socket.io: The requested module 'socket.io' does not provide an export named 'default' after upgrade to 3.0

Created on 6 Nov 2020  路  7Comments  路  Source: socketio/socket.io

Note: for support questions, please use one of these channels: stackoverflow or slack

For bug reports and feature requests for the Swift client, please open an issue there.

For bug reports and feature requests for the Java client, please open an issue there.

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

What is actually happening?

js import SocketIO from "socket.io"; export const io = SocketIO(server, { pingInterval: 10000, pingTimeout: 5000, });

Then i get an error in console:

js import SocketIO from "socket.io"; ^^^^^^^^ SyntaxError: The requested module 'socket.io' does not provide an export named 'default'

Steps to reproduce (if the current behaviour is a bug)

  1. Install socket.io 3.0 and node 15.0.1
  2. Enable type: "module" and --es-module-specifier-resolution=node
  3. Get error

Note: the best way (and by that we mean the only way) to get a quick answer is to provide a failing test case by forking the following fiddle.

Expected behaviour

Importing and running like before

What is expected?

Setup

  • OS: Mac os Catalina
  • browser: no browser
  • socket.io version: 3.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Documentation

Most helpful comment

You're right, this part was missing from the migration guide, sorry for that.

Server:

import { Server } from "socket.io";

const io = new Server(httpServer);

Client:

import io from "socket.io-client";

const socket = io();

// or, more explicit version
import { Manager } from "socket.io-client";

const manager = new Manager("https://example.com");
const socket = manager.socket("/");

All 7 comments

I tried to upgrade but before i started to change settings etc i couldn't even import it from the package, how do i solve that?

Same here with:
import * as socketIo from 'socket.io' io = socketIo(server)
"This expression is not callable"

I got it working with

import {Server, Socket} from 'socket.io'; const io = new Server(server);

But after it: be aware to update the client-side to 3.0.0 too!
https://github.com/socketio/socket.io-client

You're right, this part was missing from the migration guide, sorry for that.

Server:

import { Server } from "socket.io";

const io = new Server(httpServer);

Client:

import io from "socket.io-client";

const socket = io();

// or, more explicit version
import { Manager } from "socket.io-client";

const manager = new Manager("https://example.com");
const socket = manager.socket("/");

This is not only missing in the migration guide, the npm readme describes the old API as well.

The guides are still outdated and this is the fourth post that talks about typescript and where I finally find the solution :D

The documentation was updated here: https://socket.io/docs/v3/server-initialization/#Syntax

Was this page helpful?
0 / 5 - 0 ratings

Related issues

varHarrie picture varHarrie  路  3Comments

doughsay picture doughsay  路  4Comments

MyMomSaysIAmSpecial picture MyMomSaysIAmSpecial  路  4Comments

gCurtisCT picture gCurtisCT  路  4Comments

stnwk picture stnwk  路  4Comments