Skip to content

Commit 56224db

Browse files
authored
docs: update zod typescript issue troubleshooting with new version (#8600)
[New version of zod solves zod issues.](https://x.com/colinhacks/status/1966261915115782654). Updated troubleshooting.
1 parent 22ef25d commit 56224db

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

content/docs/08-migration-guides/26-migration-guide-5-0.mdx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ You need to update the following packages to the following versions in your `pac
2626

2727
Additionally, you need to update the following peer dependencies:
2828

29-
- `zod` package: `3.25.0` or later
29+
- `zod` package: `4.1.8` or later (recommended to avoid TypeScript performance issues)
3030

3131
An example upgrade command would be:
3232

3333
```
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
3535
```
3636

3737
<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.
4243
</Note>
4344

4445
## Codemods
@@ -3101,7 +3102,11 @@ import {
31013102

31023103
### TypeScript Performance Issues with Zod
31033104

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"`:
31053110

31063111
```json
31073112
{

content/docs/09-troubleshooting/12-typescript-performance-zod.mdx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ The AI SDK 5 has specific compatibility requirements with Zod versions. When imp
2020

2121
## Solution
2222

23-
### Update TypeScript Configuration
23+
### Upgrade Zod to 4.1.8 or Later
2424

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"`:
2636

2737
```json
2838
{
@@ -33,20 +43,4 @@ The recommended solution is to update your `tsconfig.json` to use `moduleResolut
3343
}
3444
```
3545

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

Comments
 (0)