gradio: TypeError: Cannot set property WebSocket of # which has only a getter / Gradio App not working in NextJS

Describe the bug

I can’t find anything that resolves my specific issue.

I’m trying to make a fetch request to my HuggingFace space via the Gradio app on my NextJS project, but I’m getting the following error:

TypeError: Cannot set property WebSocket of #<Object> which has only a getter at eval (webpack-internal:///(rsc)/./node_modules/@gradio/client/dist/index.js:282:34)

  • error node_modules@gradio\client\dist\index.js (271:24) @ eval
  • error unhandledRejection: Error [TypeError]: Cannot set property WebSocket of #<Object> which has only a getter at eval (webpack-internal:///(rsc)/./node_modules/@gradio/client/dist/index.js:282:34) { digest: undefined }

Does anyone know if there’s a way to resolve this, or know what’s going on here that I can fix?

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

For private reasons, I have removed the names of the actual response picture and Hugging Face space.

`import { client } from “@gradio/client”;

const HF_ACCESS_TOKEN = process.env.HF_ACCESS_TOKEN

export default async function getDetections() {

const response = await fetch("jpg");
const exampleImage = await response.blob();

const app = await client("HF_Name/MLDetector", { hf_token: HF_ACCESS_TOKEN });

const result = await app.predict("/predict", [
    exampleImage, 	// blob in 'img' Image component
]);

}`

Screenshot

Capture

Logs

No response

System Info

Gradio Environment Information:
Operating System:  Windows


gradio version:  3.38.0   

gradio Dependencies:      
  aiofiles: 23.1.0        
  aiohttp: 3.8.5
  altair: 5.0.1
  fastapi: 0.100.0        
  ffmpy: 0.3.1
  gradio-client: 0.2.10
  httpx: 0.24.1
  huggingface-hub: 0.16.4
  jinja2: 3.0.2
  markdown-it-py: 2.2.0
  markupsafe: 2.0.1
  matplotlib: 3.7.1
  mdit-py-plugins: 0.3.3
  numpy: 1.24.3
  orjson: 3.9.2
  packaging: 23.1
  pandas: 1.3.4
  pillow: 9.5.0
  pydantic: 1.10.11
  pydub: 0.25.1
  python-multipart: 0.0.6
  pyyaml: 6.0
  requests: 2.26.0
  semantic-version: 2.10.0
  typing-extensions: 4.7.1
  uvicorn: 0.23.1
  websockets: 11.0.3


gradio_client version:  0.2.10

gradio_client Dependencies:
  fsspec: 2023.6.0
  httpx: 0.24.1
  huggingface-hub: 0.16.4
  packaging: 23.1
  requests: 2.26.0
  typing-extensions: 4.7.1
  websockets: 11.0.3

Severity

Blocking usage of gradio

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Comments: 29 (10 by maintainers)

Most upvoted comments

Any updates or workarounds on this?

Sorry guys, finally had some time to take a second look at this and figured out why my previous PR wasn’t working as intended: #5840 . !global.Websocket needed to be !global.WebSocket. Apologies for the silly mistake. I’ll have some free time in the next ~48 hours to submit a new PR and test the change locally, but if a team member could make the change before then, that would also be great. Again, apologies for not catching this earlier and blocking people’s projects.

For anyone curious, this commit was the culprit

If it is undefined but can’t be assigned then the client won’t work without some other changes. I’ll take a closer look at this as soon as I can.

Why was this closed it is still not fixed

@TommeZ You can follow this PR for when the next version is released: https://github.com/gradio-app/gradio/pull/5831 Should be resolved for v0.5.2

We haven’t released a new version of the client just yet, but will be soon (in the next day or so)

I’m currently working on a way to replicate the issue, by creating a new repo that doesn’t use my company’s code. Will share once complete. But it appears so far that fetching data from Hugging Face via Gradio generates this error when run inside a Next.js project.