如何将此 node.js 模块降级到特定版本并防止以后自动升级?

How to downgrade this node.js module to specific version and prevent automatic upgrade later?

我正在使用 node.js Nodemailer 模块并遇到以下错误;

[Error: Unsupported configuration, downgrade Nodemailer to v0.7.1 or see the migration guide https://github.com/andris9/Nodemailer#migration-guide]

我查看了我的 package.json 并意识到它是 "nodemailer": "^1.8.0", 版本。

我如何降级到 v0.7.1 并防止以后在 运行 npm update 时自动升级?

如果您恰好需要 v0.7.1,请使用 "nodemailer": "0.7.1",删除 node_modules 下的 nodemailer 并再次 运行 npm install

另一种方法是 运行 命令:

npm remove nodemailer
npm install nodemailer@0.7.1 --save

使用此命令安装 0.7 版本的 nodemailer 否则发送电子邮件时会报错

npm install nodemailer@0.7.1 --save

var nodemailer = require("nodemailer");

var smtpTransport = nodemailer.createTransport("SMTP",{
   service: "Gmail",
   auth: {
       user: "EMAIL",
       pass: "PASSWORD"
   }
});

var mail = {
    from: "FROM@gmail.com",
    to: "TO@gmail.com",
    subject: "Send Email Using Node.js",
    text: "Node.js New world for me",
    html: "<b>Node.js New world for me</b>"
}

smtpTransport.sendMail(mail, function(error, response){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }

    smtpTransport.close();
});