Server Action is throwing error when building app
Unanswered
Singapura posted this in #help-forum
SingapuraOP
Hello,
and below is client component:
"use server";
import { setTimeout } from "node:timers/promises";
type SendContactEmailProps = {
success: boolean;
error: boolean;
};
export const sendContactEmail = async (_previousState: unknown, formData: FormData): Promise<SendContactEmailProps> => {
try {
console.log("line # 13", Object.fromEntries(formData.entries()));
await setTimeout(10_000);
return { success: true, error: false };
} catch (error) {
console.log("🚀 -------------------------------------------------🚀");
console.log("🚀 ~ route.ts:7 ~ sendContactEmail ~ error:", error);
console.log("🚀 -------------------------------------------------🚀");
return { success: false, error: true };
}
};
and below is client component:
const formik = useFormik({
initialValues: {
...initial values
},
validationSchema: Yup.object({
....validations
}),
onSubmit: async (values, helpers) => {
try {
helpers.setSubmitting(true);
const formData = new FormData();
// appending the values
startTransition(() => {
formAction(formData);
});
helpers.setSubmitting(false);
} catch (error) {
helpers.setSubmitting(false);
}
},
});
2 Replies
SingapuraOP
so now when I am running
npm run build
getting below error:.next/types/app/api/send-mail/route.ts:12:13
Type error: Type 'OmitWithTag<typeof import("C:/Users/dhaval/Desktop/Coursera Learning/Free_Projects/dv-rajpath-advocates/src/app/api/send-mail/route"), "config" | "generateStaticParams" | "revalidate" | ... 12 more ... | "PATCH", "">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'sendContactEmail' is incompatible with index signature.
Type '(_previousState: unknown, formData: FormData) => Promise<SendContactEmailProps>' is not assignable to type 'never'.
10 |
11 | // Check that the entry is a valid entry
> 12 | checkFields<Diff<{
| ^
13 | GET?: Function
14 | HEAD?: Function
15 | OPTIONS?: Function
Static worker exited with code: 1 and signal: null
any help why I am getting this error