socketio / socketio/socket.io

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

Open
#5,160 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
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

  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:

  • 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.