transitive-bullshit / agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.
https://agentic.so
MIT License
16.22k stars 2.12k forks source link

TypeError: Class extends value #<Object> is not a constructor or null #568

Closed nayan27 closed 3 months ago

nayan27 commented 1 year ago

Verify latest release

Verify webapp is working

Environment details

Node 14.18.1 Mac Monterey 12.6.2 Chrome Version 113.0.5672.92 (Official Build) (x86_64)

Vite - React Project with the following Package.json:

{
    "name": "browser-esm-vite-react",
    "scripts": {
        "dev": "vite",
        "build": "tsc && vite build",
        "serve": "vite preview",
        "simpleserver": "node ../node_modules/yaserver/bin/yaserver --root ./dist --port 9999"
    },
    "dependencies": {
        "axios": "^1.4.0",
        "chatgpt": "^5.2.4",
        "debounce": "^1.2.1",
        "openai": "^3.2.1",
        "react-query": "^3.39.3"
    },
    "devDependencies": {
        "@types/debounce": "^1.2.1",
        "@types/react": "^17.0.39",
        "@types/react-dom": "^17.0.11",
        "@vitejs/plugin-react": "^1.1.4",
        "autoprefixer": "^10.4.14",
        "monaco-editor": "^0.32.0",
        "postcss": "^8.4.23",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "tailwindcss": "^3.3.2",
        "typescript": "^5.0.2",
        "vite": "^2.9.13"
    }
}

Describe the Bug

Attempting to use the library in a hook function:

import { useMutation, useQueryClient } from 'react-query';
import { ChatGPTUnofficialProxyAPI } from 'chatgpt'

interface Params {
    prompt: string,
    previousMessageId?: string
}

const useChatGptPrompt = (path: string) => {
  const api = new ChatGPTUnofficialProxyAPI({
    accessToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1UaEVOVUpHTkVNMVFURTRNMEZCTWpkQ05UZzVNRFUxUlRVd1FVSkRNRU13UmtGRVFrRXpSZyJ9.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL3Byb2ZpbGUiOnsiZW1haWwiOiJzZXZpZ255Lnlhbmlja0BnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZX0sImh0dHBzOi8vYXBpLm9wZW5haS5jb20vYXV0aCI6eyJ1c2VyX2lkIjoidXNlci1UTGJ3MWpmZ1Z5VVUzWTR3Vzl1MlNSU2IifSwiaXNzIjoiaHR0cHM6Ly9hdXRoMC5vcGVuYWkuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDJ8MTE0ODM2MDI5NTU2NTUwNjM4ODI1IiwiYXVkIjpbImh0dHBzOi8vYXBpLm9wZW5haS5jb20vdjEiLCJodHRwczovL29wZW5haS5vcGVuYWkuYXV0aDBhcHAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTY4Mjk2ODgzMiwiZXhwIjoxNjg0MTc4NDMyLCJhenAiOiJUZEpJY2JlMTZXb1RIdE45NW55eXdoNUU0eU9vNkl0RyIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwgbW9kZWwucmVhZCBtb2RlbC5yZXF1ZXN0IG9yZ2FuaXphdGlvbi5yZWFkIG9mZmxpbmVfYWNjZXNzIn0.vWSG6RubKZUiXdwRwxiDpKkQyEK7mXm7ekln-A6gGcIuWaUMONGriSbK_nHO3EO2KTgKZ5EqNICXXy2WOV1Cq4gnH8_u89SY3gdP---rOW9J9wxwvPFiFyAQQ6PCOUH8JRpu_EeUcAjMz8HSJr_61Cs90bvKNzT3leTl6p6pX7vE14f34rfhhs94Ct2XukpblVAv1VLCyPwl_O8A_As8HUGfcCaTHbML56KZGcLNsZbZw6dV9hC13WlAmJ7J_1DG2lEcs6z8Z2JtU6S2yfMLn6vAxntzuGMBx-65GjUNLrK35A0zyV-iX6Y3S9YzTv3Zg-2H5WZofj1oqFk_OQlUQQ"
  });

  return useMutation(
    async ({prompt, previousMessageId}: Params) => {

      let res = null;
      if(previousMessageId && previousMessageId !== '') {
        res = await api.sendMessage(prompt, {
            parentMessageId: previousMessageId
        })
      }
      else {
        res = await api.sendMessage(prompt)
      }
      console.log("ChatGPT Response: " + JSON.stringify(res));
      return res;
    }
  );
};

export default useChatGptPrompt;
Screen Shot 2023-05-15 at 11 33 03 AM

Getting the error message above.

blueluu commented 1 year ago

I have the same problem, Looking forward to a resolution。

skeiromar commented 1 year ago

same problem

1111-stu commented 1 year ago

same problem

waterpepene commented 1 year ago

I was having this issue, solved it by: npm uninstall keyv npm install keyv Worked fine afterwards.

bitdom8 commented 1 year ago

Doesn't work https://github.com/transitive-bullshit/chatgpt-api/issues/568#issuecomment-1618257116

NOT WORKS

"npm uninstall keyv npm install keyv Worked fine afterwards."

waterpepene commented 1 year ago

I just tried again on a different computer. Went inside node_modules/keyv/src/index.js and changed the first two lines to this.

// 'use strict';

import EventEmitter from 'events';

Not sure if this step is necessary, but i then did npm uninstall keyv. It worked fine afterwards.

Sorry if this doesn't work, I'm just hoping this helps someone else!

Martin-Gregory-LG commented 1 year ago

This has proven to be an impassable issue for me. None of the solutions work

Martin-Gregory-LG commented 1 year ago

This has proven to be an impassable issue for me. None of the solutions work

It's likely this can be solved if I better understood Vite and it's internal support for NodeJs methods. But a hacky solution that worked for me was to remove class extension type, along with the invocation of super()

class Keyv extends EventEmitter {
    constructor(uri, {emitErrors = true, ...options} = {}) {
        super();

class Keyv {
    constructor(uri, {emitErrors = true, ...options} = {}) {
        // super();

don't forget to force vite to rebuild npm run vite --force

noel-schenk commented 9 months ago

It's just missing Node events in the browser:

npm i events --save

harryli0088 commented 6 months ago

@noel-schenk your solution worked for me! Thank you!!

transitive-bullshit commented 3 months ago

This project is undergoing a major revamp; closing out old issues as part of the prep process.

The chatgpt package is pretty outdated at this point. I recommend that you use the openai package or the openai-fetch package instead.