You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/08-migration-guides/26-migration-guide-5-0.mdx
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,19 +26,20 @@ You need to update the following packages to the following versions in your `pac
26
26
27
27
Additionally, you need to update the following peer dependencies:
28
28
29
-
-`zod` package: `3.25.0` or later
29
+
-`zod` package: `4.1.8` or later (recommended to avoid TypeScript performance issues)
30
30
31
31
An example upgrade command would be:
32
32
33
33
```
34
-
npm install ai @ai-sdk/react @ai-sdk/openai zod@3.25.0
34
+
npm install ai @ai-sdk/react @ai-sdk/openai zod@^4.1.8
35
35
```
36
36
37
37
<Note>
38
-
If you encounter TypeScript performance issues after upgrading, update your
39
-
`tsconfig.json` to use `moduleResolution: "nodenext"`. See the [TypeScript
40
-
performance troubleshooting
41
-
guide](/docs/troubleshooting/typescript-performance-zod) for more details.
38
+
If you encounter TypeScript performance issues after upgrading, ensure you're
39
+
using Zod 4.1.8 or later. If the issue persists, update your `tsconfig.json`
40
+
to use `moduleResolution: "nodenext"`. See the [TypeScript performance
41
+
troubleshooting guide](/docs/troubleshooting/typescript-performance-zod) for
42
+
more details.
42
43
</Note>
43
44
44
45
## Codemods
@@ -3101,7 +3102,11 @@ import {
3101
3102
3102
3103
### TypeScript Performance Issues with Zod
3103
3104
3104
-
If you experience TypeScript server crashes, slow type checking, or errors like "Type instantiation is excessively deep and possibly infinite" when using Zod with AI SDK 5.0, update your `tsconfig.json` to use `moduleResolution: "nodenext"`:
3105
+
If you experience TypeScript server crashes, slow type checking, or errors like "Type instantiation is excessively deep and possibly infinite" when using Zod with AI SDK 5.0:
3106
+
3107
+
1.**First, ensure you're using Zod 4.1.8 or later** - this version includes a fix for module resolution issues that cause TypeScript performance problems.
3108
+
3109
+
2. If the issue persists, update your `tsconfig.json` to use `moduleResolution: "nodenext"`:
Copy file name to clipboardExpand all lines: content/docs/09-troubleshooting/12-typescript-performance-zod.mdx
+13-19Lines changed: 13 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,19 @@ The AI SDK 5 has specific compatibility requirements with Zod versions. When imp
20
20
21
21
## Solution
22
22
23
-
### Update TypeScript Configuration
23
+
### Upgrade Zod to 4.1.8 or Later
24
24
25
-
The recommended solution is to update your `tsconfig.json` to use `moduleResolution: "nodenext"`:
25
+
The primary solution is to upgrade to Zod version 4.1.8 or later, which includes a fix for this module resolution issue:
26
+
27
+
```bash
28
+
pnpm add zod@^4.1.8
29
+
```
30
+
31
+
This version resolves the underlying problem where different module resolution settings were causing TypeScript to load the same Zod declarations twice, leading to expensive structural comparisons.
32
+
33
+
### Alternative: Update TypeScript Configuration
34
+
35
+
If upgrading Zod isn't possible, you can update your `tsconfig.json` to use `moduleResolution: "nodenext"`:
26
36
27
37
```json
28
38
{
@@ -33,20 +43,4 @@ The recommended solution is to update your `tsconfig.json` to use `moduleResolut
33
43
}
34
44
```
35
45
36
-
This resolves the TypeScript performance issues while allowing you to continue using the standard Zod import:
37
-
38
-
```typescript
39
-
import { z } from'zod'; // Works correctly with nodenext module resolution
40
-
```
41
-
42
-
### Alternative: Use the Zod Version-Specific Import Path
43
-
44
-
If the above solution doesn't resolve the issue, you can try importing Zod using a version-specific import path:
45
-
46
-
```typescript
47
-
// ❌ Potentially problematic: Standard import may cause TypeScript issues
48
-
import { z } from'zod';
49
-
50
-
// ✅ Alternative: version-specific import that may help with compatibility
51
-
import { z } from'zod/v4';
52
-
```
46
+
This resolves the TypeScript performance issues while allowing you to continue using the standard Zod import.
0 commit comments