9
votes

I'm trying to use socket.io for my react/flask project and every time I require socket.io in my app.js file, node fails to compile and I get this message.

Failed to compile.

./node_modules/engine.io/lib/server.js

Module not found: Can't resolve 'uws' in 'C:\Users\Walker\Desktop\xxxxx\xxxxx\node_modules\engine.io\lib'

I've tried manually installing uws with node, but nothing changes. I also used create-react-app on another computer and installed socket.io but I'm getting the same error. I followed many 'Getting Started' articles but I'm continuously getting the same error. Anyone know what could be wrong?

2
uws, node and npm versions? - Suresh Prajapati
turns out uws is deprecated, also if this is just the client and not the actual socket.io server, then you should definitely use socket.io-client - Urasquirrel

2 Answers

17
votes

So I just had this same issue, but for a very different reason. Currently when I install the latest socket.io server package from npm uws will not be found.

This is happening because the publisher of uws has recently uploaded an empty package deleting all of the actual code D:

You can fix this by installing the last non destroyed release

yarn add [email protected] npm install [email protected]

Link to empty / deprecated package: https://www.npmjs.com/package/uws

Insightful background info from reddit: https://www.reddit.com/r/node/comments/91kgte/uws_has_been_deprecated/

I'm going to post this in the top few results that come up when searching for this issue as it took me a while to figure out what was up and hopefully this will save someone out there some time!

8
votes

Try using socket.io-client

Here is the code:

import openSocket from 'socket.io-client';

const socket = openSocket(myURL);