transitive-bullshit / chatgpt-api

Node.js client for the official ChatGPT API. 🔥

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation

cuongdnv2307 opened this issue · comments

Verify latest release

  • I verified that the issue exists in the latest chatgpt release

Verify webapp is working

  • I verify that the ChatGPT webapp is working properly for this account.

Environment details

Node version : v18.16.1
Windows 11

Describe the Bug

I got the below error

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
at ChatGPTAPI.fetchCallImpl (main.js?attr=NWlR-sncM9PvO9IsjgmYJYLNIizg-ac57kqKv5nTKmfgLQ2njijxl0idxUoSQhvA:2923:25)
at window.fetch [as _fetch] (main.js?attr=NWlR-sncM9PvO9IsjgmYJYLNIizg-ac57kqKv5nTKmfgLQ2njijxl0idxUoSQhvA:2925:55)
at Promise.then.promptTokens (chatgpt-api.ts:251:1)
at new Promise ()
at ChatGPTAPI.sendMessage (chatgpt-api.ts:182:1)
at async example (App.js:12:1)

same issue, chatgpt@5.2.5 on chrome

workaround:

    const api = new ChatGPTAPI({
      apiKey,
      // workaround for https://github.com/transitive-bullshit/chatgpt-api/issues/592
      fetch: self.fetch.bind(self),
    })

solution for macOS

const api = new ChatGPTAPI({
      apiKey,
      fetch: window.fetch.bind(window),
  })
commented

same issue on Chrome version 122.0.6261.112 macOS (arm64)
image

workaround:

    const api = new ChatGPTAPI({
      apiKey,
      // workaround for https://github.com/transitive-bullshit/chatgpt-api/issues/592
      fetch: self.fetch.bind(self),
    })

I did solve the fetch problem in the above way, but there were new problems.

   chatgpt.js?v=4d2c40ad:386 Uncaught (in promise) ReferenceError: Buffer is not defined
    at Object.stringify [as serialize] (chatgpt.js?v=4d2c40ad:386:16)
    at chatgpt.js?v=4d2c40ad:589:28
    at async ChatGPTAPI._defaultUpsertMessage (chatgpt.js?v=4d2c40ad:2158:5)
    at async Promise.all (:5173/index 0)
await in (匿名)(异步)