Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: API.Completions is not a constructor #897

Open
1 task done
NatoBoram opened this issue Jun 12, 2024 · 1 comment
Open
1 task done

TypeError: API.Completions is not a constructor #897

NatoBoram opened this issue Jun 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@NatoBoram
Copy link

NatoBoram commented Jun 12, 2024

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

Calling new OpenAI() fails when Sentry is preloaded.

❯ node --import @sentry/node/preload ./dist/index.js
TypeError: API.Completions is not a constructor
    at new OpenAI (file:///home/nato/Code/github.com/NatoBoram/bug-report-sentry/node_modules/.pnpm/[email protected]/node_modules/openai/index.mjs:46:28)
    at file:///home/nato/Code/github.com/NatoBoram/bug-report-sentry/dist/openai.js:3:23
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)
(node:394397) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

To Reproduce

  1. Set Up Profiling with Sentry
  2. Use Late Initialization with ESM
  3. Call new OpenAI()

Code snippets

This is the code that fails:

import OpenAI from "openai"
const openai = new OpenAI()

It fails when the project is started with node --import @sentry/node/preload.

OS

Pop!_OS 22.04 LTS x86_64

Node version

v22.3.0

Library version

^4.51.0

@matt-casey
Copy link

Hi @NatoBoram
Looks like there is a fix being worked on over in the getsentry/sentry-javascript#12414 issue discussion.
Let me know if there's anything I can do to help from my end beyond what is being worked on with DataDog/import-in-the-middle#103, otherwise I'll check back in on this once that change lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants