Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import/require Socket class. returns 'undefined' #3726

Closed
dmaker3000 opened this issue Dec 11, 2020 · 4 comments
Closed

Can't import/require Socket class. returns 'undefined' #3726

dmaker3000 opened this issue Dec 11, 2020 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@dmaker3000
Copy link

Version 3:
const {Socket} = require('socket.io') //according to index.d.ts declaration
console.log(Socket) //=>undefined!

Version 2 (for reference):
const Socket = require('socket.io/lib/socket') //ok. /lib/socket no longer exists in version 3

@NicolaiLassen
Copy link

I'm facing the same problem with the client library.

@darrachequesne
Copy link
Member

Hi! I could indeed reproduce.

Out of curiosity, why do you need a direct reference to the Socket class?

@dmaker3000
Copy link
Author

Hi! I could indeed reproduce.

Out of curiosity, why do you need a direct reference to the Socket class?

For extending the socket class methods :)

darrachequesne added a commit to socketio/socket.io-client that referenced this issue May 6, 2021
Before this change, `require("socket.io-client").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: socketio/socket.io#3726
darrachequesne added a commit that referenced this issue May 6, 2021
Before this change, `require("socket.io").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: #3726
@darrachequesne
Copy link
Member

This should be fixed by d65b6ee, included in socket.io@4.0.2.

Thanks for the report 👍

@darrachequesne darrachequesne added this to the 4.0.2 milestone May 7, 2021
@darrachequesne darrachequesne added the bug Something isn't working label May 7, 2021
sunrise30 added a commit to sunrise30/socket.io-client that referenced this issue Jan 8, 2022
Before this change, `require("socket.io-client").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: socketio/socket.io#3726
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Before this change, `require("socket.io").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: socketio#3726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants