Nuxt 3 Nodemailer 模块 Elasticmail 配置 TypeScript 错误。’No overload matches this call.’

huangapple go评论49阅读模式
英文:

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 &#39;{ host: string; port: string; auth: { user: string; pass: string; }; }&#39; is not assignable to parameter of type &#39;TransportOptions | Transport&lt;unknown&gt;&#39;.
Object literal may only specify known properties, and &#39;host&#39; does not exist in type &#39;TransportOptions | Transport&lt;unknown&gt;&#39;.

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: &quot;smtp.elasticemail.com&quot;,
        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.

huangapple
  • 本文由 发表于 2023年5月10日 11:08:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定