收藏
回答

引入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);


}


});


}


})


最后一次编辑于  03-31  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

1 个回答

  • 娇华
    娇华
    04-04

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

    04-04
    赞同
    回复 1
    • 张
      04-08

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

      04-08
      回复