TypeScript compilation errors in backend environment
Problem
Confirm this is a Node library issue and not an underlying OpenAI API issue - [X] This is an issue with the Node library Describe the bug Hello, I recently encountered several TypeScript compilation errors when using this library in a backend project. The issue primarily seems related to missing DOM types. Here are the errors I encountered when I run `tsc` command: [code block] For reference, my tsconfig.json is as follows: [code block] While adding the `dom` library to `lib` of my tsconfig.json does seem to resolve these errors, it causes references in other parts of the code to inadvertently change, leading to build failures. Furthermore, I believe that adding the dom library to a backend codebase isn't appropriate. I've verified that the problem is not related to React's StrictMode. Upon checking the openai library's tsconfig.json, I noticed it uses the skipLibCheck option, but adding that to my project's configuration did not resolve the issue. I wanted to raise this issue here to check if it's a known issue, or if there are any recommended workarounds. Any assistance or guidance would be appreciated. Thank you. To Reproduce 1. yarn add openai 2. run `tsc` on my repository 3. See error Code snippets _No response_ OS macOS Node version Node v18.4.0 Library version openai v4.8.0
Error Output
error TS2304: Cannot find name 'AbortController'.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: TypeScript compilation errors in backend environment
Is your code importing like `import OpenAI from 'openai'` or like `import OpenAI from 'openai/src'`? Or not at all? The `src` directory within our package isn't intended to be imported or typechecked, it's only there for reference in sourcemaps. I haven't checked this, but you might need `"exclude": ["cdk.out", "node_modules", "../../node_modules"]` – it's surprising that you're excluding node_mo
Trust Score
2 verifications
- 1
Is your code importing like `import OpenAI from 'openai'` or like `import OpenAI
Is your code importing like `import OpenAI from 'openai'` or like `import OpenAI from 'openai/src'`? Or not at all? The `src` directory within our package isn't intended to be imported or typechecked, it's only there for reference in sourcemaps.
- 2
I haven't checked this, but you might need `"exclude": ["cdk.out", "node_modules
I haven't checked this, but you might need `"exclude": ["cdk.out", "node_modules", "../../node_modules"]` – it's surprising that you're excluding node_modules from being checked and still getting errors there.
Validation
Resolved in openai/openai-node GitHub issue #363. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep