Reputation: 3
I'm having issues with TypeError in the Next.js API routes folder. I'm receiving the same error over and over again "Cannot convert a Symbol value to a string", but there are no types that have Symbol, nor would it be converted to a string. The only thing I can think of is the error message shown below, but I've tried fixing that and still no luck. Below is /api/email/meetingNotification
and is called in a POST using the Fetch API:
/api/email/meetingNotification
import { NextResponse } from 'next/server';
import MeetingNotification from "../../../../../emails/meetingNotification";
import { resend } from '@/utils/resend';
interface EmailData {
schoolName: string;
email: string;
clubName: string;
meetingDate: string;
meetingTime: string;
meetingDescription: string;
meetingName: string;
location: string;
type: string;
mandatory: boolean;
meetingId: string;
clubCode: string;
}
export async function POST(request: Request) {
const emails: EmailData[] = await request.json();
try {
const emailPromises = emails.map(({
schoolName,
email,
clubName,
meetingDate,
meetingTime,
meetingDescription,
meetingName,
location,
type,
mandatory,
meetingId,
clubCode
}: EmailData) => {
return resend.emails.send({
from: `${clubName} <${clubCode}@clubcentric.org>`,
to: email,
subject: `A new meeting has been scheduled for ${clubName}`,
react: MeetingNotification({
schoolName,
location,
type,
clubName,
meetingDate: new Date(meetingDate).toDateString(),
meetingId,
meetingTime,
meetingDescription,
meetingName,
mandatory,
})
});
});
await Promise.all(emailPromises);
return NextResponse.json({ status: 'Ok' }, { status: 200 });
} catch (e: unknown) {
console.error('Failed to send emails:', e);
return NextResponse.json(
{ error: 'Internal server error. Please try resending the emails.' },
{ status: 500 }
);
}
}
sendMeetingNotification();
if (meetingData.meeting_data.push_notification) {
const { data: membershipsData, error: membershipsError } = await supabase
.from('memberships')
.select('user_id')
.eq('club_id', userId);
if (membershipsError) {
console.error('Error fetching memberships:', membershipsError.message);
toast.error("There was an error: Memberships Unavailable")
return;
}
const emails = [];
for (const member of membershipsData) {
const { data: userDirectoryData, error: userDirectoryError } = await supabase
.from('user_directory')
.select('email')
.eq('user_id', member.user_id);
if (userDirectoryError) {
console.error('Error fetching user directory:', userDirectoryError.message);
toast.error("There was an error: User Directory Unavailable")
continue;
}
for (const members of userDirectoryData) {
emails.push({
schoolName: clubSchool,
email: members.email,
clubName: clubName,
meetingDate: selectedDate?.toISOString(),
meetingTime: `${startTime} - ${endTime}`,
meetingDescription: meetingData.meeting_data.description,
meetingName: meetingData.meeting_data.title,
mandatory: meetingData.meeting_data.mandatory,
clubCode: clubCode,
location: meetingData.meeting_data.location,
type: selectedType,
meetingId: meetingData.meeting_id,
});
}
}
// Send POST request to the endpoint
const response = await fetch('/api/email/meetingNotification', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(emails),
});
if (!response.ok) {
console.error('Failed to send emails:');
toast.error("Notification System Error!")
} else {
console.log('Emails sent successfully');
router.push("/dashboard/club/meetings")
}
} else {
console.log('Push notifications are disabled: Emails not sent!');
}
}
Any help would be appreciated!
I've tried asking Claude and other AI to find a solution, they haven't been able to. Additionally, I've searched everywhere for any Symbol types, but there are none. This is the error message:
Failed to send emails: TypeError: Cannot convert a Symbol value to a string
at _ (/Users/musamalik/Downloads/[redacted]/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:254562)
at Object.get (/Users/musamalik/Downloads/[redacted]/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:254683)
at Proxy.toString (<anonymous>)
at MeetingNotification (webpack-internal:///(rsc)/./emails/meetingNotification.tsx:319:93)
at eval (webpack-internal:///(rsc)/./src/app/api/email/meetingNotification/route.ts:19:95)
at Array.map (<anonymous>)
at POST (webpack-internal:///(rsc)/./src/app/api/email/meetingNotification/route.ts:14:38)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/musamalik/Downloads/[redacted]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:63251
Upvotes: 0
Views: 436