SocketIO import on shared worker causes: "Failed to execute 'importScripts' on 'WorkerGlobalScope'"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63.2k
- Forks
- 10.3k
- Avg merge
- 11d 20h
- Merged PRs (30d)
- 2
Description
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
- Create a shared worker within any react app, and import socketIO in the shared worker like so:
import { io } from 'socket.io-client';
-
In your react app, call this shared worker (can perform any task, the import is what causes the issue)
-
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:
- Device: Lenovo ThinkBook 15p
- OS: Ubuntu
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shared worker entry point and compare the production build's generated chunk URL with the importScripts error. Reproduce the issue using a production build, then verify that the worker loads the Socket.IO import without the duplicated static/js path and that development builds remain functional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- build-system, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100