英文:
Nuxt 3 Nodemailer module Elasticmail configuration typescript error. 'No overload matches this call.'
问题
I am integrating an elasticmail to my app using the nodemailer module. Here is my configuration:
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: config.apiSecret.MAIL_SERVER,
port: config.apiSecret.MAIL_PORT,
auth: {
user: config.apiSecret.MAIL_USER,
pass: config.apiSecret.MAIL_PASSWORD
}
})
The issue is, I am seeing this error on the host
property:
No overload matches this call. The last overload gave the following error. Argument of type '{ host: string; port: string; auth: { user: string; pass: string; }; }' is not assignable to parameter of type 'TransportOptions | Transport<unknown>'. Object literal may only specify known properties, and 'host' does not exist in type 'TransportOptions | Transport<unknown>'.
I am new to typescript so I don't really know how to fix these errors. Anyone has the same experience?
英文:
I am integrating an elasticmail to my app using the nodemailer module. Here is my configuration
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: config.apiSecret.MAIL_SERVER,
port: config.apiSecret.MAIL_PORT,
auth: {
user: config.apiSecret.MAIL_USER,
pass: config.apiSecret.MAIL_PASSWORD
}
})
<!-- end snippet -->
The issue is, I am seeing this error on the host
property
No overload matches this call.
The last overload gave the following error.
Argument of type '{ host: string; port: string; auth: { user: string; pass: string; }; }' is not assignable to parameter of type 'TransportOptions | Transport<unknown>'.
Object literal may only specify known properties, and 'host' does not exist in type 'TransportOptions | Transport<unknown>'.
I am new to typescript so I don't really know how to fix these errors. Anyone has the same experience?
答案1
得分: 1
I had the same issue with nodemailer module before with typescript on the API route.
My issue was solved by changing the host to a plain string. Instead of using the useRuntimeConfig
composable the same thing for the port
. You transporter values would be like this.
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: "smtp.elasticemail.com",
port: 2525,
auth: {
user: config.apiSecret.MAIL_USER,
pass: config.apiSecret.MAIL_PASSWORD
}
})
I am not sure if that will fix your issue but you try it because my issue is similar to yours before.
英文:
I had the same issue with nodemailer module before with typescript on the API route.
My issue was solved by changing the host to a plain string. Instead of using the useRuntimeConfig
composable the same thing for the port
. You transporter values would be like this.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const config = useRuntimeConfig()
const transporter = nodemailer.createTransport({
host: "smtp.elasticemail.com",
port: 2525,
auth: {
user: config.apiSecret.MAIL_USER,
pass: config.apiSecret.MAIL_PASSWORD
}
})
<!-- end snippet -->
I am not sure if that will fix your issue but you try it because my issue is similar to yours before.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论