Skip to content

TypeError: Cannot read private member from an object whose class did not declare it at __classPrivateFieldGet #1590

Closed as not planned

Description

@FaresKi

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

When running my code in production, I got this very random error:

TypeError: Cannot read private member from an object whose class did not declare it at __classPrivateFieldGet 

(file:///app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/openai/internal/tslib.mjs:14:15) at Proxy.buildURL
(/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/openai/src/client.ts:446:23) at Proxy.buildRequest 
(/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/openai/src/client.ts:818:22) at Proxy.makeRequest 
(/app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/openai/src/client.ts:532:46) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async file:///app/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@opentelemetry+_6b14e933d3433c65dede7732832881c4/node_modules/@langchain/openai/dist/embeddings.js:182:29 at async RetryOperation._fn (/app/node_modules/.pnpm/[email protected]/node_modules/p-retry/index.js:50:12)

What's strange is that this error typically happens in a container with a Linux environment. In my case, Ubuntu.
I've tried to replicate it but I simply cannot.
Considering downgrading for now but I'm not sure if it's a "langchain/openai" issue, or an "openai" one.

To Reproduce

I'm not even sure, I'm sorry.
i'm creating the openai client via langchain:

new ChatOpenAI({
     apiKey: process.env.OPENAI_API_KEY,
     modelName: "gpt-4o",
})

Code snippets

OS

Ubuntu

Node version

v22.17.1

Library version

openai 5.10.1

Activity

  1. added
    bug
    on Jul 18, 2025
  2. RobertCraigie commented on Jul 22, 2025

    @RobertCraigie
    Contributor

    Thanks for the report, can you share more details about your setup? How are you running your code?

  3. UNLRN commented on Jul 22, 2025

    @UNLRN

    We've started to see this error as well. It started occurring when upgrading the package from 5.9.2 to 5.10.1, and oddly, downgrading didn't resolve this issue for us. This also only seems to be occurring for our calls that are using the images.generate functions. Our chat.completions.create are having no issues.

    We're making these calls inside a typescript node server (v22). I'm not familiar with the typescript setup but if that's useful information, I can share. I will say that our source code is being compiled to commonjs using swc, so we're importing the openai .js files. Our code is simple enough where we're just creating the client and then calling the API:

    export function createImage() {
      // create client
      const client = new OpenAI({ apiKey: 'XXX' });
    
      // generate image
      const response = client.images.generate(/* ... */); // errors here
    
      // process response
    }

    As far as I can tell, the issue (as reported), points to both of the "private" class fields causing issues, here and here.

    Once I patched the package to modify the "__classPrivateFieldSet/Get", I know longer see this issue for the image calls.

  4. FaresKi commented on Jul 22, 2025

    @FaresKi
    Author

    @RobertCraigie this issue occurs in my langchain setup.
    More specifically, in Langgraph, using the Tavily web search feature.

    Now based on @UNLRN's comment, i too had to downgrade far down the road to get it to work as expected
    Let me find the exact version
    Edit: had to downgrade to a full major version below (4.10) for it work

  5. nbonamy commented on Jul 23, 2025

    @nbonamy

    I am seeing this too when using the Response API in an Electron app (calling the API from the renderer process).

    This happens when doing await this.client.responses.create(request)

    Call-stack on 5.10.2 is:

    Error while generating text TypeError: Cannot read private member from an object whose class did not declare it
        at __classPrivateFieldGet (tslib.mjs:14:15)
        at Proxy.buildURL (client.ts:446:23)
        at Proxy.buildRequest (client.ts:818:22)
        at Proxy.makeRequest (client.ts:532:46)
    

    Apparently offending line:

    const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
    

    Thanks

  6. marcelgerber commented on Jul 24, 2025

    @marcelgerber

    Hi! I was also facing this issue, and like @FaresKi could not repro this locally, but only on the server.

    Turns out, the culprit is a Sentry dependency update we had recently: @sentry/[email protected] (which also explains why I couldn't repro locally, because I didn't have Sentry set up for instrumentation on localhost).

    I tested three versions of @sentry/node:

    • 9.39 works fine
    • 9.40 (released a week ago) is broken, and leads to the above error
    • 9.41 (released today) is also still broken

    Interestingly, the 9.40 release notes are talking about an OpenAI integration, instrumenting openAI API calls. I guess that's the culprit, then (although I don't have this integration enabled currently).

  7. nbonamy commented on Jul 24, 2025

    @nbonamy

    Turns out, the culprit is a Sentry dependency update we had recently: @sentry/[email protected] (which also explains why I couldn't repro locally, because I didn't have Sentry set up for instrumentation on localhost).

    I don't depend on Sentry and still facing the issue.

  8. marcelgerber commented on Jul 24, 2025

    @marcelgerber

    I could find a minimal repro for the Sentry problem, and have filed that with them now: getsentry/sentry-javascript#17159

  9. UNLRN commented on Jul 24, 2025

    @UNLRN

    @marcelgerber Thanks for that. It seems like this was also our issue. Downgrading sentry to 9.39 worked for us with using the latest openai version.

  10. nbonamy commented on Jul 24, 2025

    @nbonamy

    In my case downgrading openai to 4.104.0 fixes the problem. Tried to the smallest upgrade to 5.0.2 and things start to fail.

    Interestingly, things work in an isolated node project (https://github.com/nbonamy/multi-llm-ts). In the electron project (https://github.com/nbonamy/witsy), things fail. Given the number of dependencies there, hard to know which one is the problem...

  11. SkinnnyJay commented on Sep 14, 2025

    @SkinnnyJay

    🚑 #1648

  12. luizzappa commented on Oct 26, 2025

    @luizzappa

    In my case this error was caused by Vue’s reactivity proxy wrapping the OpenAI client instance. Classes with ECMA private fields (#x) break when accessed through a Proxy, which leads to:

    TypeError: Cannot read private member from an object whose class did not declare it
        at __classPrivateFieldGet (...)
        at Proxy.buildURL (...)
        at Proxy.buildRequest (...)
        at Proxy.makeRequest (...)

    How I reproduced it (simplified)

    import { ref } from "vue";
    import OpenAI from "openai";
    
    const clientRef = ref<OpenAI | null>(null);
    // ❌ Problematic: storing the client in a Vue ref/reactive wraps it in a Proxy
    clientRef.value = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
    
    // Later:
    await clientRef.value!.chat.completions.create({ /* ... */ });
    // -> throws: Cannot read private member...

    Fix / Workarounds

    Keep the client out of reactivity, or explicitly mark it as non-reactive:

    import { markRaw, shallowRef, toRaw } from "vue";
    import OpenAI from "openai";
    
    const clientRef = shallowRef<OpenAI | null>(null);
    clientRef.value = markRaw(new OpenAI({ apiKey: process.env.OPENAI_API_KEY! }));
  13. nbonamy commented on Oct 28, 2025

    @nbonamy

    @luizzappa thanks for this! exactly my situation and your fix works!

  14. added
    upstream
    on Jul 6, 2026
  15. HAYDEN-OAI commented on Aug 14, 2026

    @HAYDEN-OAI
    Contributor

    Thanks for reporting this. The SDK intentionally uses JavaScript private fields, which require methods to run with the original client instance as their receiver. Proxy integrations should bind wrapped methods to their original instance. If you use Sentry, upgrade to a version containing its upstream receiver-binding fix; if you use Vue, store the client with markRaw or shallowRef. We are not planning to remove runtime-enforced private fields from the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsdkupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions