'm encountering an error using the OpenAI Node.js SDK in my Discord bot’s gptModule.js
file. The error is as follows:
TypeError: Configuration is not a constructor
Here’s the relevant code snippet:
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
I have verified the following:
-
The OpenAI library is up to date and the import statements are correct.
-
The
OPENAI_API_KEY
environment variable is set correctly. -
I am using Node.js version v22.11.0.
Additionally, I have tried:
-
Deleting the
node_modules
directory andpackage-lock.json
file, and then reinstalling dependencies. -
Running the code in different versions of the Node.js environment.
Despite these efforts, the issue persists. If anyone has experienced a similar problem or has suggestions for resolving this, I would greatly appreciate your help!