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

Moving from 4.1.3 to 4.2.0 -> xmlhttprequest-ssl' relative to engine.io-client error #1494

Closed
hardcodet opened this issue Sep 16, 2021 · 15 comments
Labels
bug Something isn't working
Milestone

Comments

@hardcodet
Copy link

Describe the bug

I was toying around with socket.io in codesandbox.io, and experienced a crash pretty much right away. When switching to 4.1.3, the error went away:

ModuleNotFoundError
Could not find module in path: 'xmlhttprequest-ssl' relative to '/node_modules/engine.io-client/lib/transports/index.js'

To Reproduce

  • codesandbox.io/
  • add a reference to 4.2.0 and initialize a socket -> will crash
  • downgrade to 4.1.3 -> workd

Please fill the following code example:

Socket.IO server version: x.y.z

Client (4.2.0)

mport { io, Socket } from "socket.io-client";
import { config } from "./config";

export class SocketClient {
  socket: Socket;

  constructor() {
    this.socket = io("http://localhost:3000", {});
  }
}
@hardcodet hardcodet added the bug Something isn't working label Sep 16, 2021
@darrachequesne
Copy link
Member

We used a fork of xmlhttprequest-ssl, until the changes were merged upstream. We have removed our fork in [email protected], which may explain (or at least, be linked to) your issue: socketio/engine.io-client@2de8b4e

But switching version should properly resolve the dependencies, so I guess it's a problem with codesandbox?

@alpha-titan
Copy link

There are some bugs in the 4.2.0 client, I am not able to connect to the server.

I have enabled CORS on the socket server as well as the express server

I was stuck at this issue for hours tried everything no luck establish a WebSocket connection with the server, finally downgraded to 4.1.3

The below code works on 4.1.3 and doesn't work on 4.2.0

const [socket, setSocket] = useState();
const handleSocket = () => {
        newSocket = io("ws://localhost:4000");
	newSocket.connect();
	console.log(newSocket.connected);
        setSocket(newSocket);
}
useEffect(()=>{
         handleSocket();
},[setSocket])

Upon inspecting Network for ws connections

using 4.1.3 connection is created

Screenshot 2021-09-20 at 11 11 07 PM

using 4.2.0 pending

Screenshot 2021-09-20 at 11 13 34 PM

when I use the CDN and comment out the import it works again.

@hardcodet
Copy link
Author

@darrachequesne Could well be a codesandbox issue - I just did a quick hello world there, but wanted to report it in case it would be of interest to you.

OTOH, I would assume that codesandbox generically just downloads packages as specified in package.json, so I'm not sure it could be buggy there and make any assumptions (in the end, it did end up with code that was referring to that SSL library).

@alpha-titan Looks like your issue is not related to the one reported here?

darrachequesne added a commit to socketio/socket.io-fiddle that referenced this issue Sep 21, 2021
@darrachequesne
Copy link
Member

@alpha-titan I was not able to reproduce, could you please check https://github.com/socketio/socket.io-fiddle/tree/issues/socket.io/1494? Could you please open a new issue with all necessary details?

@hardcodet I could in fact reproduce:

screenshot

I don't understand why though. A fresh "npm install" or "yarn add" both includes the xmlhttprequest-ssl package:

$ npm ls xmlhttprequest-ssl
/test
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

If someone can shed some light on this...

@alpha-titan
Copy link

@darrachequesne I have a Reactclient (created with vite.js) with version socket4.2.0and anexpress serverrunning on differentport` and I was not possible to establish a connection.

@alpha-titan
Copy link

@hardcodet Yeah sorry for that I will open a new Issue

@louisgv
Copy link

louisgv commented Sep 27, 2021

I encountered this while upgrading to 4.2.0 in react-native environment. The metro bundler gave this error:

Unable to resolve module ../../contrib/xmlhttprequest-ssl/XMLHttpRequest from P:\Projects\considr\ponde
r\native\node_modules\engine.io-client\lib\transports\index.js:

None of these files exist:

  • node_modules\engine.io-client\contrib\xmlhttprequest-ssl\XMLHttpRequest(.native|.ios.ts|.native.ts|
    .ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.
    json)
  • node_modules\engine.io-client\contrib\xmlhttprequest-ssl\XMLHttpRequest\index(.native|.ios.ts|.nati
    ve.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.
    json|.json)

1 | const XMLHttpRequest = require("xmlhttprequest-ssl");
2 | const XHR = require("./polling-xhr");
3 | const JSONP = require("./polling-jsonp");
4 | const websocket = require("./websocket");

Doing npm ls show the package was installed:

$ npm ls xmlhttprequest-ssl
`-- [email protected]
  `-- [email protected]
    `-- [email protected]

@louisgv
Copy link

louisgv commented Sep 27, 2021

It seems the core issue is that somehow the bundler is trying to resolve the package relatively from the old path (from 4.1.3). Based on the log above, it's trying to find the package in node_modules\engine.io-client\contrib\xmlhttprequest-ssl still

Maybe the dist generated still has the old artifact?

@louisgv
Copy link

louisgv commented Sep 27, 2021

Very weird - I grep through the installed code in node_modules for contrib and nothing was found. I have reinstall my dependencies a couple time and still seeing the issue.

@darrachequesne
Copy link
Member

@louisgv did you try to reset metro-s cache with --reset-cache?

Reference: https://facebook.github.io/metro/docs/troubleshooting

@jsjoeio
Copy link

jsjoeio commented Oct 3, 2021

I'm seeing a similar issue. I landed on this CodeSandbox from this article.

image

Updating "socket.io-client": "2.3.0" -> 4.2.0 results in the same error. I wonder if this is specific to CodeSandbox 🤔

@jsjoeio
Copy link

jsjoeio commented Oct 3, 2021

darrachequesne added a commit to socketio/engine.io-client that referenced this issue Oct 14, 2021
It seems vite has issues with absolute dependencies in the "browser"
field, so we'll provide a quick workaround.

Related:

- socketio/socket.io-client#1494
- socketio/socket.io-client#1495
@darrachequesne
Copy link
Member

This should be fixed in version 4.3.1. Could you please check?

@jsjoeio
Copy link

jsjoeio commented Oct 27, 2021

This should be fixed in version 4.3.1. Could you please check?

Apologies. I ran into this in Codesandbox. I assume the only way I could check is if Codesandbox upgraded, right? Unless there is an easier way to check?

@darrachequesne
Copy link
Member

This should be fixed by socketio/engine.io-client@4971914, included in version 4.3.1.

Please reopen if needed.

@darrachequesne darrachequesne added this to the 4.3.1 milestone May 12, 2022
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

5 participants