ai icon indicating copy to clipboard operation
ai copied to clipboard

Error in implementing in nodejs

Open iurvish opened this issue 1 year ago • 6 comments

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

iurvish avatar Jul 08 '24 16:07 iurvish

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

MaxLeiter avatar Jul 08 '24 20:07 MaxLeiter

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"] }

iurvish avatar Jul 10 '24 05:07 iurvish

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

lgrammel avatar Jul 11 '24 07:07 lgrammel

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]

iurvish avatar Jul 15 '24 12:07 iurvish

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

lgrammel avatar Jul 15 '24 16:07 lgrammel

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

iurvish avatar Jul 15 '24 17:07 iurvish

Encountered the same issue. Adding latest openai as a dependency resolved the issue.

Don't have proper time now to bisect where this started happening, however @lgrammel seems that the Vercel AI SDK takes a peer dependency on types from openai even for things that don't require OAI integration (AssistantStream from src/lib/AssistantStream.ts and Run from src/resources/beta/threads/runs/runs.ts). I believe there was some regression that was introduced with peer deps.

guywaldman avatar Oct 19 '24 23:10 guywaldman

For me updating ts config file solved my problem. here's what i updated:

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

iurvish avatar Nov 09 '24 16:11 iurvish