vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
8.84k stars 1.26k forks source link

Error in implementing in nodejs #2213

Open KrishnaCodez opened 3 weeks ago

KrishnaCodez commented 3 weeks ago

Description

Hi Vercel,

I'm trying to implement AI in my Node.js application, i copy paste the code that is available doc but I'm encountering an error. I'd appreciate some assistance in troubleshooting.

The error message I'm getting is:-

Code example

node_modules/@ai-sdk/ui-utils/node_modules/@ai-sdk/provider-utils/dist/index.d.ts(134,5): error TS2502: 'fetch' is referenced directly or indirectly in its own type annotation. [0] node_modules/@ai-sdk/ui-utils/node_modules/@ai-sdk/provider-utils/dist/index.d.ts(149,5): error TS2502: 'fetch' is referenced directly or indirectly in its own type annotation.
[0] node_modules/ai/dist/index.d.ts(8,33): error TS2307: Cannot find module 'openai/lib/AssistantStream' or its corresponding type declarations. [0] node_modules/ai/dist/index.d.ts(9,21): error TS2307: Cannot find module 'openai/resources/beta/threads/runs/runs' or its corresponding type declarations.

Additional context

node version v20.14.0

MaxLeiter commented 3 weeks ago

Can you please share your typescript version as well? Updating it may resolve this

KrishnaCodez commented 3 weeks ago

my ts version is "typescript": "^5.1.6"

and

tsconfig.json file :- { "compilerOptions": { "module": "NodeNext", "moduleResolution": "NodeNext", "target": "ES2022", "sourceMap": true, "outDir": "dist", "allowSyntheticDefaultImports": true }, "include": ["src/*/.ts", "src/index.ts"] }

lgrammel commented 2 weeks ago

Can you share a github repository with a minimal reproduction? I can't reproduce the issue

KrishnaCodez commented 2 weeks ago

good to see response from you... here is my repo i have used turbo monorepo i have been trying to implement ai in backend.... for security reason i have removed my frontend folder

also i switch to goggle provider but same error

/../node_modules/@ai-sdk/provider-utils/dist/index.d.ts(134,5): error TS2502: 'fetch' is referenced directly or indirectly in its own type annotation. [0] ../../node_modules/@ai-sdk/provider-utils/dist/index.d.ts(149,5): error TS2502: 'fetch' is referenced directly or indirectly in its own type annotation. [0] ../../node_modules/ai/dist/index.d.ts(8,33): error TS2307: Cannot find module 'openai/lib/AssistantStream' or its corresponding type declarations. [0] ../../node_modules/ai/dist/index.d.ts(9,21): error TS2307: Cannot find module 'openai/resources/beta/threads/runs/runs' or its corresponding type declarations. [0]

lgrammel commented 2 weeks ago

@KrishnaCodez i tried your example, but i can't run yarn or another package manager successfully bc it fails to find @repo/eslint-config

KrishnaCodez commented 2 weeks ago

@lgrammel i republished repo here is the link i am using ai function in src/controller/chat-controller