0

Using "OpenAI", I am developing a plug-in for Figma. However, the following error appears and OpenAI cannot be used. How can I resolve this?

TypeError: cannot read property 'FormData' of undefined

It seems that an error has occurred in the following file, but I do not know how to solve it.

node_modules/openai/configuration.ts

Name 'require' not found.

src/code.ts

import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
  apiKey: "API KEY",
});
const openai = new OpenAIApi(configuration);

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "lib": ["es6"],
    "strict": true,
    "typeRoots": [
      "./node_modules/@types",
      "./node_modules/@figma"
    ],
    "outDir": "./dist",
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node"
  },
  "include": ["src/**/*.ts"]
}

package.json

{
  "name": "name",
  "version": "1.0.0",
  "description": "Your Figma Plugin",
  "main": "code.js",
  "scripts": {
    "build": "webpack",
    "watch": "npm run build -- --watch"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "@figma/plugin-typings": "^1.69.0",
    "openai": "^3.3.0",
    "ts-loader": "^9.4.4",
    "typescript": "^5.1.6",
    "webpack": "^5.88.1",
    "webpack-cli": "^5.1.4"
  }
}
Ika
  • 1,271
  • 1
  • 12
  • 20

0 Answers0