next.js icon indicating copy to clipboard operation
next.js copied to clipboard

I get the error when I use handlebars with next.js server actions.

Open melodyxpot opened this issue 4 months ago • 2 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32660
  Available CPU cores: 8
Binaries:
  Node: 20.17.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.0-rc.0 // Latest available version is detected (15.0.0-rc.0).
  eslint-config-next: 15.0.0-rc.0
  react: 19.0.0-rc-2d16326d-20240930
  react-dom: 19.0.0-rc-2d16326d-20240930
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which example does this report relate to?

handlebars

What browser are you using? (if relevant)

Chrome, Safari

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

I am using handlebars to use html template and I use resend to send the email by the imported html file. It is working in production and development mode in my pc but not working in only vercel.

This is my code

"use server";

import fs from "fs";
import Handlebars from "handlebars";
import path from "path";
import { Resend } from "resend";
import { BASE_URL } from "@/constants";

const resendClient = new Resend(process.env.RESEND_API_KEY);

export const sendEmail = async (
	token: string,
	email: string,
	method: "password"
) => {
	const link = `${BASE_URL}/reset-psw?email_token=${token}&email=${email}`;

	const html = renderTemplate("reset-psw-req", {
		link,
		domainName: process.env.RESEND_DOMAIN_NAME
	});

	try {
		const result = await resendClient.emails.send({
			from: `MomoReis10 Support <support@${process.env.RESEND_DOMAIN_NAME}>`,
			to: [email],
			subject: "Reset your password",
			html
		});

		return result;
	} catch (err) {
		throw new Error(err as string);
	}
};

const renderTemplate = (templateName: string, data: any) => {
	const filePath = path.join(
		process.env.NODE_ENV === "development" ? process.cwd() : __dirname,
		process.env.NODE_ENV === "development" ? "lib/emails/" : "./lib/emails",
		`${templateName}.handlebars`
	);
	const source = fs.readFileSync(filePath, "utf8");
	const template = Handlebars.compile(source);
	return template(data);
};

image

Expected Behavior

I expected to send the email to user's email for resetting password.

To Reproduce

https://momoreis.vercel.app You can see the "Giriş Yap" button in the navbar and there is the link named "Şifreni mi Unuttun?". If you click it and see the console, there is an error.

melodyxpot avatar Oct 16 '24 08:10 melodyxpot