zod icon indicating copy to clipboard operation
zod copied to clipboard

"Type instantiation is excessively deep and possibly infinite." when using Zod versions 3.23.0 and 3.23.1 together.

Open kerrigan-nm opened this issue 1 year ago • 11 comments

We have multiple projects using Zod, and are currently tripping over a compatibility issue between a project which is still on zod 3.23.0 and one which we're attempting to upgrade to 3.23.3.

Consuming the 3.23.0 schemas from 3.23.3 results in the following error, which I've also reproduced between 3.23.0 and 3.23.1.

error TS2589: Type instantiation is excessively deep and possibly infinite.

Full reproduction here, with a summary in the readme.

kerrigan-nm avatar Apr 23 '24 16:04 kerrigan-nm

I described a similar scenario here: https://github.com/colinhacks/zod/issues/3429#issuecomment-2071816685

It seems to be related to the recursive definition of ZodError. As far as I can tell this isn't related to Zod 3.23 and can be replicated with almost any two previous versions of Zod (let me know if you have evidence to the contrary though).

As I mentioned in the other issue, it's not clear what should be done about this. There are breaking changes I can make that might mitigate the problem (changing the definition of ZodError). But really modern monorepo tools and package managers have systems to avoid dependency duplication for exactly these reasons.

colinhacks avatar Apr 23 '24 16:04 colinhacks

I see what you're saying, but as some light pushback:

  1. I've never seen this degree of incompatibility between patch versions of the same project (outside of an actual bug).
  2. This significantly hampers the ability to publish a library of prefab zod schemas which would be consumed and extended by multiple consumers (our use case).
  3. npm is explicitly designed to be able to handle various versions of a single package as sub-dependencies of direct dependencies, so the total incompatibility comes as a surprise in this case.

it's not clear what should be done about this.

That's totally fair — I don't have a solution either :)

If it's a "hard problem" to solve, so be it, but I'm sure it'll keep coming up, and it might be worth identifying the root cause and figuring out a medium-to-long-term solution.

kerrigan-nm avatar Apr 23 '24 18:04 kerrigan-nm

Having similar issue – zod seems to be grinding down to a halt in a forever error loop when using 3.23.x together with vee-validate/zod.

Downgrading to 3.22.4 solved the issue for now.

chrisjansky avatar Apr 24 '24 14:04 chrisjansky

I am experiencing the same issue as well. We are dealing with a large schema that is causing a significant slowdown in the project, especially when importing the schema to our working file. We attempted to resolve the issue by downgrading to version 3.22.4, but it did not have any effect.

henriquealbert avatar Apr 25 '24 14:04 henriquealbert

I had the same issue here after upgrading to 3.23.X. Downgrading worked for me.

Ayterx avatar May 01 '24 17:05 Ayterx

I had the same issue in a mono repo with 2 packages using 3.23.6 and one using 3.23.5. I got them all on the same version and issue was fixed.

lukebelbina avatar May 06 '24 21:05 lukebelbina

Had the same issue with two repos 3.23.6 & 3.23.5. Updated 5 to 6, and the errors are gone.

catz avatar May 07 '24 14:05 catz

I have this issue with 3.23.7 and 3.23.8. Having to remain on 3.23.6 for now.

darbymanning avatar May 21 '24 09:05 darbymanning

I have this issue with 3.23.7 and 3.23.8. Having to remain on 3.23.6 for now.

This worked for me too, cheers! 🍻

benqus avatar Jun 27 '24 10:06 benqus

Having this issue with @builder.io's qwik-city package: Screenshot 2024-09-16 at 6 42 31 PM

Will investigate what's causing the issue, or see if I can find a way to consolidate the versions as previous comments have mentioned.

georgeportillo avatar Sep 17 '24 01:09 georgeportillo