简体   繁体   中英

Cannot read properties of undefined (reading 'replace')

I have problem with mailChimp integration. On localhost all works good but on deploy i have error. Cannot read properties of undefined (reading 'replace') . This is my interface


interface NewsletterFormValues {
  EMAIL: string;
}

and my function:

const {
    handleSubmit,
    register,
    formState: { errors },
  } = useForm<NewsletterFormValues>();
  const url = process.env.NEXT_PUBLIC_MAILCHIMP_URL as string;
  const { message, handleSubmit: mailChimpSubmit } = useMailChimpForm(url);
  const emailError = errors["EMAIL"];
  const onSubmit = (fields: NewsletterFormValues) => {
    mailChimpSubmit(fields as Params);
  };

and this is my input for email adress

<input
                    {...register("EMAIL", {
                      required: true,
                      pattern:
                        /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
                    })}
                    className="w-full lg:w-[458px] h-14 placeholder-black text-[16px] outline-0 py-[18px] pl-4 lg:mr-[24px] border-[1px] border-[#DDDDDC]"
                    placeholder="Email address"
                  />

看来process.env.NEXT_PUBLIC_MAILCHIMP_URL (因此url )是undefined ,当未定义的url传递给useMailChimpForm时会导致错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM