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

Error: Can't resolve 'uws' #575

Closed
1 of 2 tasks
evpozdniakov opened this issue Mar 31, 2019 · 8 comments
Closed
1 of 2 tasks

Error: Can't resolve 'uws' #575

evpozdniakov opened this issue Mar 31, 2019 · 8 comments

Comments

@evpozdniakov
Copy link

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

You want to:

  • report a bug
  • request a feature

Current behaviour

I use socket.io, therefore engine.io is one of my depended packages.
When I try to bundle my project, I have error
Module not found: Error: Can't resolve 'uws' in node_modules/engine.io/lib/server.js
(The error would not be here if I configure webpack with webpack-node-externals, but I really need all packages in a single bundle for docker container.)

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

  1. Add socket.io v2.2.0 to your existing project (which uses webpack) as a production dependency.
  2. Require it in your entry point code.
  3. Run webpack

Expected behaviour

It should create a bundle without errors.

Setup

  • OS: centOS
  • browser: server side (node.js)
  • engine.io version: 3.3.2

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

IMO it could be fixed if engine.io declares uws as a prod dependency (not a dev dependency).

@sethcwhiting
Copy link

sethcwhiting commented Apr 9, 2019

This is discussed in an issue on the socket.io repo (socketio/socket.io#3342), but I think it's more appropriate here. I found codymikol's answer very helpful:

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 uws@10.148.1
npm install uws@10.148.1

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!

This was referenced May 17, 2019
@mmdevries
Copy link

@sethcwhiting unfortunately this version doesn't work with node 10 and higher. At least if you want to use a secure connection(wss). We didn't want to step over to the javascript ws package and we created a new uws package and added support for node 10 and node 12.
This new package is based on the original uws and we merged some fixes from cws.
Maybe this will be useful for others as well.

https://github.com/mmdevries/uws

@TylerR909
Copy link

I'm running in to this same issue right now, trying to bundle server code up. Looks like uws is a devDependency despite having a require('uws') in the Server.init function. Thus it's not actually installed and webpack can't resolve it.

Thinking I can just define it as an empty module in Webpack considering I don't toggle on the uws module but it's also hard to say considering engine.io is a 3rd-level-dependency (My dependency (1) depends on socket.io (2) depends on engine.io (3)).

@Femina
Copy link

Femina commented Dec 8, 2019

Then what's the solution for this?

@goosewobbler
Copy link

@Femina installing the new uws package that @mmdevries mentioned seems to work for me so far...

@RossVertizan
Copy link

Is there a reason why uws can't be moved out of the devDependencies and into the dependencies alongside ws as @TylerR909 implied?

I had the same problem with webpack and made a local edit to the package.json and now everything is OK.

@Domiii
Copy link

Domiii commented Jan 24, 2020

If you are here because your webpack build fails - good news: There is an easy fix!

Problem Explanation

In recent socket.io versions, ws is already set as the default wsEngine. So unless you actually want to use uws, you don't have to worry about it at all because engine.io won't even require it in that case.

However, webpack does not know that. It only sees the dependency in the code, it sees require('uws'), and, not knowing that that part of the code will never execute, it will try to bundle it nevertheless.

Solution

Simply tell it to not bundle it by adding uws to your externals in your webpack.config and you are done :)

E.g.:

module.exports = {
  // ...
  externals: { 
     uws: 'uws' 
  }
};

darrachequesne added a commit that referenced this issue Jun 4, 2020
So that bundlers like webpack do not try to include it in the build.

As a side-effect, any implementation which matches the API of the ws
module can now be used.

Before that change, you had to explicitly exclude uws:

```
// webpack.config.js
module.exports = {
  // ...
  externals: {
     uws: 'uws'
  }
};
```

Related: #575
darrachequesne added a commit that referenced this issue Jun 4, 2020
So that bundlers like webpack do not try to include it in the build.

As a side-effect, any implementation which matches the API of the ws
module can now be used.

Before that change, you had to explicitly exclude uws:

```
// webpack.config.js
module.exports = {
  // ...
  externals: {
     uws: 'uws'
  }
};
```

Related: #575

Backported from master: 82cdca2
darrachequesne added a commit that referenced this issue Jun 4, 2020
So that bundlers like webpack do not try to include it in the build.

As a side-effect, any implementation which matches the API of the ws
module can now be used.

Before that change, you had to explicitly exclude uws:

```
// webpack.config.js
module.exports = {
  // ...
  externals: {
     uws: 'uws'
  }
};
```

Related: #575

Backported from master: 82cdca2
@darrachequesne
Copy link
Member

darrachequesne commented Jun 4, 2020

This should be fixed by 85e544a, included in engine.io@3.4.2.

Edit: I've updated the example here: https://github.com/socketio/socket.io/tree/master/examples/webpack-build-server

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

9 participants