Giter Club home page Giter Club logo

Comments (7)

bryanhelmig avatar bryanhelmig commented on August 17, 2024 4

Create a global.d.ts file in your project's root or type definition folder, then add the following code:

declare global {
  type File = any;
}
export {};

This should fix the issue.

from openai-node.

rjamesnw avatar rjamesnw commented on August 17, 2024 2

Note, a temporary workaround is to add type File=any; to the top of the index.d.ts file in the dist directory.

from openai-node.

TimJohns avatar TimJohns commented on August 17, 2024 1

Since it looks like you're using Node, in lieu of the workaround, you may be able to use one of the Node runtime configurations from tsconfig/bases, by adding it to your tsconfig.json with "extends".

I ran into this same issue with undefined File type in my Node 16 project, and resolved it by adding "extends": "@tsconfig/node16/tsconfig.json" to my tsconfig.json (full contents of my current working tsconfig.json below, for reference)

{
  "compilerOptions": {
      "module": "commonjs",
      "lib": ["ES2018"],
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true,
      "target": "es6",
      "noImplicitAny": true,
      "moduleResolution": "node",
      "sourceMap": true,
      "outDir": "dist",
      "baseUrl": ".",
      "paths": {
          "*": [
              "node_modules/*",
              "src/types/*"
          ]
      }
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "src/public"
  ],
  "extends": "@tsconfig/node16/tsconfig.json"
}

from openai-node.

almerindo avatar almerindo commented on August 17, 2024

It works for me! Thanks!

from openai-node.

ivanglushko avatar ivanglushko commented on August 17, 2024

Ran into this aswell

from openai-node.

rattrayalex avatar rattrayalex commented on August 17, 2024

This is fixed in our upcoming v4, which includes conveniences for file uploads.

from openai-node.

khanakia avatar khanakia commented on August 17, 2024

Non it's not solved still getting error with v4 and using ts-node with tsconfig/paths in Typescript

tsconfig.json

"ts-node": {
    "require": ["tsconfig-paths/register"]
  }
/test/node_modules/openai/_shims/formdata.js:6
exports.File = File;
               ^
ReferenceError: File is not defined
    at Object.<anonymous> (/test/node_modules/openai/_shims/formdata.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Object.require.extensions.<computed> [as .js] (/usr/local/lib/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/test/node_modules/openai/src/uploads.ts:66:15)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)

What i found tsconfig-paths is picking this file _shims/formdata.js but it should pick _shims/formdata.node.js

from openai-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.