【问题标题】:How to solve error: Cannot find module "dns" at webpackMissingModule in Ionic 3如何解决错误:在 Ionic 3 的 webpackMissingModule 中找不到模块“dns”
【发布时间】:2019-12-28 20:58:36
【问题描述】:

我正在尝试在我的 ionic 3 项目中实现 nodemailer,并按照 codeburst.io (https://codeburst.io/sending-an-email-using-nodemailer-gmail-7cfa0712a799) 的教程进行操作。

当我按照教程进行离子服务时,出现“找不到模块“dns”的错误。下图显示了我的控制台中的错误。

这是我的 .ts 文件中的代码:

constructor(){
let transporter = nodemailer.createTransport({
     service: 'gmail',
     auth: {
       user: 'XXXXX@gmail.com',
       pass: 'XXXXXXXXXXXXXXX'
     }
   });
   const mailOptions = {
     from: 'XXXXXXX@email.com', // sender address
     to: 'XXXXXXXXX@email.com', // list of receivers
     subject: 'Subject of your email', // Subject line
     html: '<p>Your html here</p>'// plain text body
   };

   transporter.sendMail(mailOptions, function (err, info) {
     if(err)
       console.log(err)
     else
       console.log(info);
  });

 }

我尝试过搜索,但找不到 Ionic 与 Angular 打字稿的解决方案。我对 DNS 的概念不熟悉,因此请提供一些指导/解释!

【问题讨论】:

    标签: typescript ionic-framework ionic3 nodemailer


    【解决方案1】:

    我想通了!我在 webpack.config 文件中添加了dns: 'empty'

    代码如下所示:

    node: {
      dns: 'empty'
    }
    

    【讨论】:

    • 请在您的答案中添加一些解释,以便其他人可以从中学习
    猜你喜欢
    • 2018-05-07
    • 2020-07-18
    • 2019-06-11
    • 1970-01-01
    • 2018-02-10
    • 2021-04-08
    • 2018-02-02
    • 2021-08-31
    • 2022-07-22
    相关资源
    最近更新 更多