zod icon indicating copy to clipboard operation
zod copied to clipboard

Zod v3.20.2 causing stalled build in CRA project

Open tornvallalexander opened this issue 2 years ago • 1 comments

Started using Zod in a create-react-app project in combination with react-hook-form. Everything works fine except building the project.

No error is thrown, the build simply freezes and is stalled. When running npm run build --verbose it just pretty much stops completely after the first initial logs that happen within approx. 20ms.

It seems to be a problem with the, at this time, latest version v3.20.2. After downgrading Zod to v3.19.1, it builds normally.

tornvallalexander avatar Dec 22 '22 14:12 tornvallalexander

Hi @tornvallalexander ! Do you have a sample repo/sandbox we can look at to be sure?

maxArturo avatar Dec 22 '22 17:12 maxArturo

I've been experiencing a similar performance issue.

TypeScript autocompletion is extremely slow in VS Code when [email protected] package is installed, the CPU usage spikes to 100% and it usually takes 3-4 seconds to load the suggestions. After removing zod or downgrading it to v3.19.1 the issue is gone. You can see more details in the related stackoverflow post I created: https://stackoverflow.com/questions/74881472/slow-typescript-autocompletion-in-vs-code-for-zod.

It's worth mentioning that this issue also occurs in Webstorm, so I'm convinced it's not VSCode-related.

xkcm avatar Dec 22 '22 21:12 xkcm

I'm experiencing similar and if I leave it long it enough it will error with error TS2589: Type instantiation is excessively deep and possibly infinite.

using a trivial schema such as

import {z} from 'zod';

export const test = z.object({
  name: z.string().optional(),
});

and running npx tsc is enough to cause the issue.

bioxeed avatar Dec 29 '22 08:12 bioxeed

@colinhacks You are still unconvinced it should have been a semver major :)?

kibertoad avatar Dec 29 '22 08:12 kibertoad

It seems like I'm unable to reproduce the behaviour within a new basic implementation with Zod and React Hook Form. The project builds normally and runs as it should. The error is still persistent in the original project where I found the issue. Then again, project where I found it is more complex in terms of general structure for forms and input fields.

tornvallalexander avatar Dec 30 '22 11:12 tornvallalexander

I had the same problem when I added de 3.20.0+ version (using nextjs + next-auth), I was using coerce to validate query params in a api request handler, I apparently solved the problem by upgrading my typescript version to 4.9.4.

Matan18 avatar Dec 30 '22 13:12 Matan18

We have the same issue in a project. The 'possibly infinite' notice takes roughly 1 hour to appear in CI.

Our project was pinned to TypeScript 4.8.2. This seems to be fixed in TypeScript 4.8.3 and 4.9.4, so perhaps try upgrading that if you're still seeing this issue.

stephank avatar Jan 02 '23 08:01 stephank

Running into the same issue using vite and vite-plugin-dts. Generating type declarations took ~35 minutes or so with no helpful output. Tried upgrading and downgrading typescript versions as recommended by @stephank to no avail. Ended up downgrading zod from 3.20.2 to 3.19.1 which resolved the problem.

This anecdote might not be too useful, but I found that the issue was only present when using z.object() with a defined field i.e. this causes a hang-up:

import { z } from 'zod';

export const mySchema = z.object({ myField: z.number() });

This does not:

import { z } from 'zod';

export const mySchema = z.object({});

emilbon99 avatar Jan 06 '23 18:01 emilbon99

I'm having the same issue.

ZOD: 3.20.2 (also tested on 3.19.1)
TSC: 4.9.4

Project build takes much longer then before and it ends with semantic error TS2589. Deletion of the node_modules, package lock file and downgrade to 3.19.1 didn't solved the problem.

In my case, something that simple like

import { z } from 'zod';

const fooSchema = z.object({
    foo: z.object({})
});

has trigger the error.

Pio-Trek avatar Jan 06 '23 22:01 Pio-Trek

Okay, I found the cause of all the problems. It seems to be TSDX 0.14.1, which can cause some weird issues with TypeScript error check because it doesn't support the latest version of TS and hasn't been updated in 2 years (!) In my case, the solution was to switch to DTS-CLI, which runs and builds super fast without any problems with Zod.

I hope this has helped someone.

Pio-Trek avatar Jan 06 '23 23:01 Pio-Trek

I needed to rollback all the way to 3.17.10 (which is the same as another lib I'm depending on...)

mckelveygreg avatar Jan 11 '23 18:01 mckelveygreg

Okay, I found the cause of all the problems. It seems to be TSDX 0.14.1, which can cause some weird issues with TypeScript error check because it doesn't support the latest version of TS and hasn't been updated in 2 years (!) In my case, the solution was to switch to DTS-CLI, which runs and builds super fast without any problems with Zod.

I hope this has helped someone.

Thank you very much, I found out that the latest version of tsdx 0.14.1 uses type-script version 3. I found an issue how you can rewrite package.json so that tsdx uses type-script version 4

Can't use Typescript 4 features

After updating, the problem error TS2589: Type instantiation is excessively deep and possibly infinite. is gone

motionrus avatar Jan 17 '23 17:01 motionrus

v30.20.6 still has the mentioned bugs. The build just hangs forever and intellisense (webstorm) becomes highly unresponsive.

xeinebiu avatar Feb 09 '23 15:02 xeinebiu

It also happens to me using VS Code version 1.76.2, TypeScript version 4.3.5 and Zod version 3.20.2. Pinning Zod to version 3.17.9 seems to fix the issue.

zilia-gmethot avatar Mar 17 '23 18:03 zilia-gmethot

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 15 '23 20:06 stale[bot]