Next.js Discord

Discord Forum

npm run dev works perfect, but npm run build will fail (Resend)

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Route.ts
"use server";

import { IFormData } from "@/components/pages/partners/models/IFormData";
import { Resend } from "resend";

export async function GET(formdata: IFormData) {
  const resend = new Resend(process.env.NEXT_PUBLIC_RESEND_API_KEY);
  try {
    if (process.env.NEXT_PUBLIC_EMAIL) {
      const { data } = await resend.emails.send({
        from: process.env.NEXT_PUBLIC_EMAIL,
        to: process.env.NEXT_PUBLIC_EMAIL,
        subject: formdata.subject,
        html: `
               Some HTML
            `,
      });
      if (!data) return;
      return data;
    }
  } catch (error) {
    return Response.json({ error });
  }
}


Error:
Type error: Type '{ __tag__: "GET"; __param_position__: "first"; __param_type__: IFormData; }' does not satisfy the constraint 'ParamCheck<Request | NextRequest>'.
  Types of property '__param_type__' are incompatible.
    Type 'IFormData' is not assignable to type 'Request | NextRequest'.

  31 |     Diff<
  32 |       ParamCheck<Request | NextRequest>,
> 33 |       {
     |       ^
  34 |         __tag__: 'GET'
  35 |         __param_position__: 'first'
  36 |         __param_type__: FirstArg<MaybeField<TEntry, 'GET'>>


IFormData.ts
export interface IFormData {
    firstName: string;
    lastName: string;
    email: string;
    phone: string;
    subject: string;
    message: string;
}
Answered by joulev
uhm, is that a route.ts file? rename the file. server actions are not route handlers and need not be declared in route handlers file. also server actions need not be named GET or POST or similar and need not return a Response
View full answer

7 Replies

Answer
Cape lionOP
Okay, thanks for the help!
Renamed the file to sendMail.ts
I got a atleast a new error ;)) Will see if I can try to fix this error.

Function (updated):
export async function sendMail(formdata: IFormData): Promise<boolean> {
  const resend = new Resend(process.env.NEXT_PUBLIC_RESEND_API_KEY);
  try {
    if (process.env.NEXT_PUBLIC_EMAIL) {
      const { data } = await resend.emails.send({
        from: process.env.NEXT_PUBLIC_EMAIL,
        to: process.env.NEXT_PUBLIC_EMAIL,
        subject: formdata.subject,
        html: `
               Some HTML
            `,
      });
      if (!data) return false;
      return true;
    }
    return false;
  } catch (error) {
    throw error;
    // return Response.json({ error });
  }
}


New error:
Type error: Type 'OmitWithTag<typeof import("D:/Coding/GitHub/Strafwerk/app/page"), "metadata" | "default" | "config" | "generateStaticParams" | "revalidate" | "dynamic" | "dynamicParams" | "fetchCache" | ... 5 more ... | "generateViewport", "">' does not satisfy the constraint '{ [x: string]: never; }'.
  Property 'Page' is incompatible with index signature.
    Type '() => React.JSX.Element' is not assignable to type 'never'.

   6 |
   7 | // Check that the entry is a valid entry
>  8 | checkFields<Diff<{
     |             ^
   9 |   default: Function
  10 |   config?: {}
  11 |   generateStaticParams?: Function
Cape lionOP
You are so wonderfull!
You can mark it as answered