socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
60.98k stars 10.1k forks source link

SocketIO import on shared worker causes: "Failed to execute 'importScripts' on 'WorkerGlobalScope'" #5160

Open JoshAvakian opened 1 month ago

JoshAvakian commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

Using 4.7.5, when running a production build utilizing shared workers, socket.IO import causes a DOMException. Development builds and virtual environment (localhost) do not have this issue

To Reproduce

  1. Create a shared worker within any react app, and import socketIO in the shared worker like so:
import { io } from 'socket.io-client';
  1. In your react app, call this shared worker (can perform any task, the import is what causes the issue)

  2. Run a production build using yarn

When opening the new production build, worker file will not run, and opening the console on the shared worker will look like this:

"Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://yourApp/static/js/static/js/3002.2646329c.chunk.js' failed to load."

When removing the socket.io import and re-running the build, the worker will no longer throw this error.

Expected behavior No importScripts error is thrown, and shared workers can open their own socket session.

Platform:

Additional context Please note that a development build and a local environment will not throw this error in the shared worker. We discovered it only after we ran a production build using yarn

JoshAvakian commented 1 month ago

This looks similar to #3809