0

I am facing this error while running my backend in my React app:

file:///D:/Project/server/route/dalle.routes.js:3
import { Configuration, OpenAIApi} from 'openai';
         ^^^^^^^^^^^^^
SyntaxError: The requested module 'openai' does not provide an export named 'Configuration'

What's wrong?

Rok Benko
  • 14,265
  • 2
  • 24
  • 49
  • https://stackoverflow.com/questions/76917525/module-has-no-exported-member-when-importing-from-openai/76917692#76917692 – Yilmaz Aug 19 '23 at 11:56
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 19 '23 at 13:23

1 Answers1

0

First, check the OpenAI NodeJS SDK version:

  • OPTION 1 - using the terminal: npm list openai or
  • OPTION 2 - by looking at the package.json file.

What do you get/see? You probably have the OpenAI NodeJS SDK v4.

Problem

You have v4, but you want to use the code that works with v3. SDK v4 was released on August 16, 2023, and is a complete rewrite of the SDK. Among other things, there are changes in the initialization logic. See the v3 to v4 migration guide.

Solution

Change this...

// Old (i.e., OpenAI NodeJS SDK v3)
import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

...to this.

// New (i.e., OpenAI NodeJS SDK v4)
import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});
Rok Benko
  • 14,265
  • 2
  • 24
  • 49