adapter-react-hook-form icon indicating copy to clipboard operation
adapter-react-hook-form copied to clipboard

Type instantiation is excessively deep and possibly infinite.

Open MeesEgberts opened this issue 6 months ago • 1 comments

When passing a zod schema to the zodResolver like this:

const schema = useUpdateNameSchema();

const { form, handleSubmitWithAction } = useHookFormAction(
    updateName,
    zodResolver(schema),
    {
      formProps: {
        defaultValues: {
          name: user?.name || "",
        },
      },
    },
  )

It throws this error: Type instantiation is excessively deep and possibly infinite.

MeesEgberts avatar May 26 '25 09:05 MeesEgberts

Without knowing much about this particular issue, this "Excessively deep" issue is likely fixed in Zod 4.1.6: https://github.com/colinhacks/zod/pull/5222.

If you are using Zod 3.x, you can fix this issue by updating your tsconfig to use a modern module/moduleResolution setting instead of the legacy "node": https://x.com/colinhacks/status/1966261915115782654

To the maintainers: if you haven't already, I recommend checking out the Library Authors guide for best practices around peer dependencies and accepting user-defined schemas: https://zod.dev/library-authors

colinhacks avatar Sep 11 '25 23:09 colinhacks