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

[socket.io-client 2] Unable to run on webpack >= 5 #1565

Closed
giovanni-bertoncelli opened this issue Nov 16, 2022 · 6 comments
Closed

[socket.io-client 2] Unable to run on webpack >= 5 #1565

giovanni-bertoncelli opened this issue Nov 16, 2022 · 6 comments
Labels
needs investigation This issue needs further investigations v2 This issue affects Socket.IO v2

Comments

@giovanni-bertoncelli
Copy link

giovanni-bertoncelli commented Nov 16, 2022

Describe the bug
Since I have upgraded an Angular 13 app to Angular 14, that underneath uses webpack@5.74.0, the socket.io-client has a lot of issues and became unusable. All the nodejs polyfills for the ws dependency are gone so I got these kind of errors:

./node_modules/node-gyp-build/index.js:5:9-22 - Error: Module not found: Error: Can't resolve 'os' in '/Users/giovannibertoncelli/workspace/geo/frontend/node_modules/node-gyp-build'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
	- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "os": false }

I had to redirect all these dependencies to make it work:

     "zlib": [
        "node_modules/browserify-zlib"
      ],
      "net": [
        "node_modules/net-browserify/"
      ],
      "tls": [
        "node_modules/tls-browserify/"
      ],
      "assert": [
        "node_modules/assert-browserify"
      ],
      "crypto": [
        "node_modules/crypto-browserify"
      ],
      "https": [
        "node_modules/https-browserify"
      ],
      "http": [
        "node_modules/stream-http"
      ],
      "stream": [
        "node_modules/stream-browserify"
      ],
      "timers": [
        "node_modules/timers-browserify"
      ],
      "os": [
        "node_modules/os-browserify"
      ],
      "fs": [
        "node_modules/browserify-fs"
      ]

That's very frustrating since these dependencies where not required before the ng upgrade and I have no actual use for these in my main package.json.

After resolving this issue I've encontered another issue, at runtime:

Uncaught SyntaxError: Unexpected eval or arguments in strict mode

That, I presume, comes from the tls dependency:

image

In order to avoid all this I've installed isomorphic-ws and replaced the ws dependency with this package. Then it has no nodejs dependencies and compiles correctly.

To Reproduce

Socket.IO server version: 2.4.1
Socket.IO client version: 2.5.0

Expected behavior
Should compile correctly.

Platform:

  • Device: MacBook Pro
  • OS: macOS Monterey 12.6
@giovanni-bertoncelli giovanni-bertoncelli added the to triage Waiting to be triaged by a member of the team label Nov 16, 2022
@darrachequesne
Copy link
Member

Hi @giovanni-bertoncelli , could you please provide a project reproducing the issue? That would help a lot, thanks.

@giovanni-bertoncelli
Copy link
Author

@darrachequesne https://codesandbox.io/s/serene-thunder-edirx3?file=/tsconfig.json here you can find a similar behaviour

@darrachequesne
Copy link
Member

@giovanni-bertoncelli thanks, I could indeed reproduce. I'm investigating.

@giovanni-bertoncelli
Copy link
Author

It may be similar to this issue @darrachequesne: #1088
Maybe it's actually the same behaviour

@darrachequesne darrachequesne added needs investigation This issue needs further investigations v2 This issue affects Socket.IO v2 and removed to triage Waiting to be triaged by a member of the team labels Nov 16, 2022
@darrachequesne
Copy link
Member

I'm not able to reproduce with a project created with @ng/cli: https://github.com/socketio/socket.io-fiddle/tree/angular-sio-v2

Could it be linked to the CodeSandbox platform?

@giovanni-bertoncelli
Copy link
Author

Don't think so... the issue compared initially in a local project.. maybe try with a ng14 project locally on your machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation This issue needs further investigations v2 This issue affects Socket.IO v2
Projects
None yet
Development

No branches or pull requests

2 participants