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

Webpack 5 / Vite breaks socket.io-client v2.4.0 #2568

Closed
FossPrime opened this issue Feb 25, 2022 · 1 comment
Closed

Webpack 5 / Vite breaks socket.io-client v2.4.0 #2568

FossPrime opened this issue Feb 25, 2022 · 1 comment

Comments

@FossPrime
Copy link
Member

FossPrime commented Feb 25, 2022

Steps to reproduce

I've been getting very close to migrating a feathers4 client to vite. My last hurdle is socket.io-client a CommonJS module that expects to be built with Webpack 4, as it uses Node.js only APIs and hard coded Webpack specific polyfills.

The first error you'll get is TypeError: url.parse is not a function, which can be addressed by installing the url npm package manually.

The second I get is something that transpiles to this line, from engine.io-client's xmlhttprequest-ssl

"TypeError: doRequest is not a function
    at XMLHttpRequest.send (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:2473:21)
    at Request.create (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4200:13)
    at new Request (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4122:12)
    at XHR.request (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4077:14)
    at XHR.doPoll (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4091:22)
    at XHR.Polling.poll (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:3940:12)
    at XHR.Polling.doOpen (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:3905:12)
    at XHR.Transport.open (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:3381:14)
    at Socket.open (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4827:17)
    at new Socket (https://30n1s.sse.codesandbox.io/node_modules/.vite/socket_io-client.js?v=7119379e:4747:12)"

Expected behavior

socket.io should connect.

Actual behavior

socket.io is full of Node.js dependencies that are hard to shim on Webpack 5 backed browser bundlers like Vite.

System configuration

Module versions: Feathers 4
NodeJS version: 16
Module Loader: Vite 2


I'll work on this next week and hopefully file the solution / workaround.

@FossPrime FossPrime changed the title Webpack 5 / Vite breaks socket.io v2.4.0 Webpack 5 / Vite breaks socket.io-client v2.4.0 Feb 25, 2022
@FossPrime
Copy link
Member Author

This is a known common issue with a lot of socket.io-client versions, luckily there is a good workaround, manually resolving the problematic xmlhttprequest-ssl module to the one provided by engine.io-client/lib/xmlhttprequest-ssl.js

vitejs/vite#4798 (comment)

vitejs/vite#6586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant