Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Heap out of memory in Next.js project #104

Open
desiboli opened this issue Mar 31, 2023 · 3 comments
Open

JS Heap out of memory in Next.js project #104

desiboli opened this issue Mar 31, 2023 · 3 comments

Comments

@desiboli
Copy link

desiboli commented Mar 31, 2023

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I have a pretty simple form component.
When importing makeZodI18nMap I'm getting the heap out of memory error and I'm not able to lint or build my code.

I'm using it like this:

 import { makeZodI18nMap } from 'zod-i18n-map';
 //.....
  const { t } = useTranslation(['common', 'login']);
  z.setErrorMap(makeZodI18nMap({ t ));
 //....

When commenting the following lines out, I'm able to lint and build my code again.

am I doing something wrong here, or could this possibly be a bug in zod-i18n ?

@desiboli desiboli changed the title Getting JS Heap out of memory in Next.js project JS Heap out of memory in Next.js project Mar 31, 2023
@zowebs
Copy link

zowebs commented Apr 10, 2023

Hello,
I have just tried to build the Next.js project using next-i18next and everything went fine. Iam using turborepo (but I think this should not have effect on your issue)

Are you setting the map on each occurence of zod or just once?
Iam setting the translations just once in my generic useForm hook. ;)

@desiboli
Copy link
Author

Hi!
ok cool, so it's working fine fore you ?

the makeZodI18nMap you mean ? I just tried it on one component once, that failed as mentioned.
Would love to see your generic useForm hook 🙏

@zowebs
Copy link

zowebs commented Apr 10, 2023

There you go:
..btw, useTranslation from my @utils/translation is just reexported useTranslation from next-i18next.

import {
  useForm as useFormRHF,
  FieldValues,
  UseFormProps,
  useFieldArray,
  FormProvider,
  useFormContext,
} from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import z, { ZodType } from 'zod'
import { makeZodI18nMap } from 'zod-i18n-map'
import { useTranslation } from '@utils/translation'

interface UseFormCustom {
  validationSchema: ZodType
}

export const useForm = <T extends FieldValues, TContext = unknown>({
  validationSchema,
  ...props
}: UseFormProps<T, TContext> & UseFormCustom) => {
  const { t } = useTranslation('zod')
  z.setErrorMap(makeZodI18nMap({ t }))

  return useFormRHF<T, TContext>({
    ...props,
    resolver: zodResolver(validationSchema),
  })
}

export { useFieldArray, FormProvider, useFormContext }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants