Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in implementing in nodejs #2213

Closed
KrishnaCodez opened this issue Jul 8, 2024 · 8 comments
Closed

Error in implementing in nodejs #2213

KrishnaCodez opened this issue Jul 8, 2024 · 8 comments
Labels
ai/core ai/ui bug Something isn't working

Comments

@KrishnaCodez
Copy link

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
Copy link
Member

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

@KrishnaCodez
Copy link
Author

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
Copy link
Collaborator

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

@KrishnaCodez
Copy link
Author

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
Copy link
Collaborator

@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
Copy link
Author

KrishnaCodez commented Jul 15, 2024

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

@lgrammel lgrammel added bug Something isn't working ai/ui labels Sep 19, 2024
@guywaldman
Copy link

guywaldman commented Oct 19, 2024

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.

@KrishnaCodez
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/core ai/ui bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants