收藏
回答

引入npm模块后报错

报错信息如下:




VM860:1 thirdScriptError 


 sdk uncaught third Error 


 module "miniprogram_npm/nodemailer/events" is not defined 


 Error: module "miniprogram_npm/nodemailer/events" is not defined


    at require (http://127.0.0.1:59882/appservice/__dev__/WAService.js:1:1015979)


    at http://127.0.0.1:59882/appservice/__dev__/WAService.js:1:1015729


    at __REQUIRE__ (http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:31:34)


    at http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:660:12


    at Object.module.exports.map.../shared [as func] (http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:231:24)


    at __REQUIRE__ (http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:37:23)


    at http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:226:12


    at Object.module.exports.map../mailer [as func] (http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:71:18)


    at __REQUIRE__ (http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:37:23)


    at http://127.0.0.1:59882/appservice/miniprogram_npm/nodemailer/index.js:11430:10


console.error @ VM860:1


(anonymous) @ WAService.js:1


(anonymous) @ WAService.js:1


e @ appservice?t=1554034994106:1095


window.onerror @ VM860:1


scriptLoaded @ appservice?t=1554034994106:1127


script.onload @ appservice?t=1554034994106:1139




代码如下:


'use strict';


const nodemailer = require('nodemailer');




// import { nodemailer } from '../../miniprogram_npm/nodemailer/index.js'


Page({


data: {




},




onLoad: function() {





},


sendEmail:function(){


var transporter = nodemailer.createTransport({


service: 'qq',


auth: {


user: '1469677378@qq.com',


pass: 'eqyldhtoxlfvfigc'


}


});




var mailOptions = {


from: '1469677378@qq.com',


to: 'whuisszh@gmail.com',


subject: 'Sending Email using Node.js',


text: 'That was easy!'


};




transporter.sendMail(mailOptions, function (error, info) {


if (error) {


console.log(error);


} else {


console.log('Email sent: ' + info.response);


}


});


}


})


回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员-娇华
    社区技术运营专员-娇华
    2019-04-04

    你好,请问问题是否已解决?

    2019-04-04
    有用
    回复 1
    • 码汪
      码汪
      2019-04-08

      解决了,nodemeailer模块不能直接导入使用。要先建立一个服务器,在服务器里使用nodeemailer。

      2019-04-08
      回复
登录 后发表内容