I have Nuxt app, and a very simple server handler for the contact form (using nodemailer). Locally everything is working fine, but on the server i get the next error:
{
"url": "/api/contact",
"statusCode": 500,
"statusMessage": "",
"message": "Class extends value #<Object> is not a constructor or null",
"stack": ""
}
And this the handler:
export default defineEventHandler(async (event) => {
try {
const body = await readBody(event)
const { error } = contactSchema.validate(body)
if (error) {
throw new Error(`Invalid request body: ${error.message}`)
}
const { name, email, tel, message } = body
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: config.SMTP_HOST,
port: 587,
secure: false,
auth: {
user: config.SMTP_USER,
pass: config.SMTP_PASS,
},
})
const mailOptions = {
from: `Website form" <${config.SMTP_EMAIL}>`,
to: config.SMTP_EMAIL,
subject: `Webform - Name: ${name}`,
html: `
<p>Name: ${name}</p>
<p>Phone: ${tel}</p>
<p>Email: ${email}</p>
<p>${message}</p>
`,
}
// Send the email
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(`Error: ${error}`)
} else {
console.log('Email sent: ' + info.response)
}
})
return { code: 200, message: 'Email sent successfully' }
} catch (error) {
console.error(error)
return { code: 500, message: 'Failed to send email' }
}
})
does somebody know what could be the cause of this?