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

4.40.0 -> 4.40.1: Breaking change - OpenAI is not a constructor #816

Closed
1 task done
YasharF opened this issue May 2, 2024 · 18 comments
Closed
1 task done

4.40.0 -> 4.40.1: Breaking change - OpenAI is not a constructor #816

YasharF opened this issue May 2, 2024 · 18 comments
Labels
bug Something isn't working

Comments

@YasharF
Copy link

YasharF commented May 2, 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

Based on numbers, 4.40.1 is supposed to be a bug fix release over 4.40.0, so I didn't expect something to break. I have not tested the application after 4.40.1 to see if anything else is broken.

const openai = new OpenAI({
^

TypeError: OpenAI is not a constructor

To Reproduce

Code saved as test.js:

const openaiKey = "a valid OpenAI key"
const OpenAI = require('openai');

const openai = new OpenAI({
	apiKey: openaiKey,
});

 >> npm install openai@4.40.0
 >> node test.js
(no errors.)
 >> npm install openai@4.40.1
 >> node test.js
 const openai = new OpenAI({
               ^

TypeError: OpenAI is not a constructor
 >> npm install openai@4.40.0
 >> node test.js
(no errors.)

Code snippets

No response

OS

WSL Ubuntu 24.04 LTS

Node version

v20.12.2

Library version

4.40.1

@YasharF YasharF added the bug Something isn't working label May 2, 2024
@bizob2828
Copy link

bizob2828 commented May 2, 2024

At New Relic we instrument this package and this behavior is causing issues. I want to echo from what @YasharF has said that this was released in a patch and is a breaking change. This works fine when doing

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

so maybe the exports in package.json need updated as well to handle CJS?

@Galkon
Copy link

Galkon commented May 2, 2024

Using this package in a project and 4.40.1 breaks production builds due to this error. Works in local development environment. Reverting to 4.40.0 fixes it.

@mtharrison
Copy link

Having a similar issue in tests where I stub OpenAI.Embeddings.prototype which has now moved to OpenAI.OpenAI.Embeddings.prototype

@Eomm
Copy link

Eomm commented May 3, 2024

This bot's PR seems the root cause 😄 #815

@RobertCraigie
Copy link
Collaborator

sorry about this, we're investigating.

@rattrayalex
Copy link
Collaborator

Thanks for reporting. Can you share your tsconfig to aid with repro?

@mahaboobkhan29
Copy link

mahaboobkhan29 commented May 3, 2024

Ah... I thought my code had some issues.
I use Express.js and didn't set ES modules in package.json, and it worked fine before, but now it's throwing an error

const OpenAI = require("openai");
const openai = new OpenAI({
    apikey: process.env.OPENAI_API_KEY
});

Error: OpenAI is not a constructor

Are you guys investigating this?

@jsumners-nr
Copy link

Thanks for reporting. Can you share your tsconfig to aid with repro?

The reproduction supplied in the opening report is plain JavaScript plus Node.js. There is no TypeScript involved.

@mtharrison
Copy link

Thanks for reporting. Can you share your tsconfig to aid with repro?

My report is also from a is in a pure JS repo. As reported above it works ok using ESM but CJS is where it fails.

@mtharrison
Copy link

mtharrison commented May 3, 2024

Minimal repro is simply:

const OpenAi = require('openai');
const client = new OpenAi();
$ node index.js
TypeError: OpenAi is not a constructor.....

@RobertCraigie
Copy link
Collaborator

this will be fixed in the next release: #818

@mahaboobkhan29
Copy link

@RobertCraigie when can we expect the fix version release in NPM

@RobertCraigie
Copy link
Collaborator

This has been fixed in v4.40.2

@poshest
Copy link

poshest commented May 3, 2024

@RobertCraigie Thank you! To whom in OpenAI may I send an invoice for the 4 hours of developer time spent troubleshooting this? ;)

@canws
Copy link

canws commented May 3, 2024

Thanks a lot , finally working this.

@dreamsavior
Copy link

This has been fixed in v4.40.2

No, this hasn’t been fixed. I’m still having the problem on the latest version, 4.51.

@ygorcarmo
Copy link

Same here but only after I tried to implement datadog.

@dgellow
Copy link
Contributor

dgellow commented Jun 18, 2024

@dreamsavior Please open another GitHub issue if you're still having problems with the latest version of the SDK

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