vercel / ai

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

TypeScript errors with Node #1403

Open mishushakov opened 5 months ago

mishushakov commented 5 months ago

Description

Using Node.js (v20.12.2) and typescript 5.4.5

tsc -p tsconfig.json
node_modules/ai/dist/index.d.ts:5:45 - error TS2307: Cannot find module '@mistralai/mistralai' or its corresponding type declarations.

5 import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
                                              ~~~~~~~~~~~~~~~~~~~~~~

node_modules/ai/dist/index.d.ts:770:19 - error TS2503: Cannot find namespace 'JSX'.

770     ui?: string | JSX.Element | JSX.Element[] | null | undefined;
                      ~~~

node_modules/ai/dist/index.d.ts:770:33 - error TS2503: Cannot find namespace 'JSX'.

770     ui?: string | JSX.Element | JSX.Element[] | null | undefined;
                                    ~~~

node_modules/ai/dist/index.d.ts:1734:24 - error TS2503: Cannot find namespace 'JSX'.

1734 type UINode = string | JSX.Element | JSX.Element[] | null | undefined;
                            ~~~

node_modules/ai/dist/index.d.ts:1734:38 - error TS2503: Cannot find namespace 'JSX'.

1734 type UINode = string | JSX.Element | JSX.Element[] | null | undefined;
                                          ~~~

Found 5 errors in the same file, starting at: node_modules/ai/dist/index.d.ts:5

Code example

import { OpenAI } from '@ai-sdk/openai';
import { LanguageModelV1 } from '@ai-sdk/provider'
import { experimental_generateObject, UserContent } from 'ai'

Additional context

My tsconfig:

{
  "compilerOptions": {
    "outDir": "dist",
    "declaration": true,
    "lib": ["ESNext", "DOM"],
    "module": "NodeNext",
    "target": "ESNext",
    "moduleResolution": "NodeNext"
  },
  "include": ["src/**/*.ts"]
}
lgrammel commented 5 months ago

Fix: https://github.com/vercel/ai/pull/1406

mishushakov commented 5 months ago

Awesome! Could you also help me out with the JSX type errors? I'm not using React Danke.

lgrammel commented 5 months ago

The JSX issue is risky to fix. Can you try installing just the React types and see if that helps?

  "@types/react": "^18.2.8",
mishushakov commented 5 months ago

Fixes it for me (only getting the Mistral error now)! Can I ask you to keep this issue, because it's very non-obvious for Node users?

xdotli commented 2 weeks ago

The JSX issue is risky to fix. Can you try installing just the React types and see if that helps?

  "@types/react": "^18.2.8",

Encountering same issue on express backend without react types. Resolved by installing types as a devDependency. Maybe add this to the document for express users?

lgrammel commented 1 week ago

https://sdk.vercel.ai/docs/troubleshooting/common-issues/typescript-cannot-find-namespace-jsx