javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用

我第一次遇到这样的错误,如果我在这里没有注意到任何重要因素,请原谅我.

我运行代码时遇到的完整错误是:

(node:10812) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated. Please use `node --inspect-brk` instead.

如下图所示:

《javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用》

它还强调了这一行代码:

return new Script(code, options);

如下图所示:

《javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用》

这是我正在运行的node.js的版本,如nvm所示.

C:\Users\jonat>nvm install latest
Version 8.4.0 is already installed.

我昨天运行了VS安装程序,所以它是最新的.

这些是我正在使用的模块:

const   express                 = require("express"),
        mongoose                = require("mongoose"),
        passport                = require("passport"),
        bodyParser              = require("body-parser"),
        LocalStrategy           = require("passport-local"),
        passportLocalMongoose   = require("passport-local-mongoose"),
        math                    = require("mathjs");

它们已经通过npm安装,我最近运行.npm update,它们显示在继承文件目录中:

《javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用》

这里改变了各种设置,并设置了将要进一步使用的变量:

const app = express();

const   uri = 'mongodb://localhost/MathsWebsite',
        options = { useMongoClient: true };

mongoose.Promise = global.Promise;
mongoose.set('debug', true);

app.set('view engine','ejs');
app.use(bodyParser.urlencoded({extended:true}));
app.use(require("express-session")({
    secret:"fanatical beaver",
    resave: false,
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());

passport.use(new LocalStrategy(user.authenticate()));
passport.serializeUser(user.serializeUser());
passport.deserializeUser(user.deserializeUser());

值得注意的是我可以运行代码:

C:\Users\jonat\Documents\GitHub\MathsSite\MathsWebsite>node server.js --no-deprecation

然后导致链接错误(https://hastebin.com/lajotaqifo.rb),如下所示:

《javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用》

seed.js函数位于代码的底部,如下所示:

mongoose.connect(uri, options)
    .then(() => seedDB)
    .then(() => app.listen(process.env.PORT, process.env.IP, function () {
        console.log("Server started");
    }))
    .catch(error => console.log("error"));

导入如下:

const   seedDB                  = require("./seed");

导出如下:

async function seedDB() {...}
module.exports = seedDB;

并且位于文件目录中,如下所示:

《javascript – (node:6868)[DEP0062] DeprecationWarning:`node –inspect –debug-brk`已弃用》

我相信的这个错误与弃用的问题无关,尽管我认为最好提及它.虽然我相信我可以绕过这个问题,因为我已经表明我不认为这是长期可接受的,如果任何人都可以提供这个问题的解决方案,或者甚至只是指出我正确的方向,我将不胜感激.

(另外,如果有必要,这里是来自hastebin中server.js(https://hastebin.com/ibuweyaxes.js)和seed.js(https://hastebin.com/ibuweyaxes.js)的完整代码的链接)
另外要注意的是由于我对这个问题缺乏了解,我可能要么包含无用的东西,要么没有包含有用的东西.

最佳答案 问题在于第343行的Seed.js文件,因为错误消息正确指出,您不能在异步函数之外使用等待.虽然SeedDB可能是异步函数,但是await代码实际上在then catch语句中,然后必须将其声明为异步函数以便不出错.

从您的pastebin剪切的原始代码如下所示:

}).then(() => {

因此,只需在箭头函数之前添加async,就像我在下面所做的那样.

}).then(async () => {

这就完全是承诺:

Promise((resolve, reject) => {
        examboardData.forEach(function (examSeed) {
            examBoard.create(examSeed, function (err, exam) {
                console.log("Creating new examboard");
                if (err) {
                    console.log("Could not create new examboard\n" + err);
                }
                else {
                    console.log("Created examboard");
                    exams.push(exam);
                }
            });
        });
        questionData.forEach(function (questionSeed) {
            question.create(questionSeed, function (err, question) {
                if (err) {
                    console.log("Could not create new question\n" + err);
                }
                else {
                    console.log("Created question");
                    questions.push(question);
                }
            });
        });
    }).then(async () => {
        var topicIncrementor = 0;
        for (let question of questions) {
            for (var i = 0; i < exams.length; i++) {
                for (var t = 0; t < exams[i].modules.length; t++) {
                    for (var q = 0; q < exams[i].modules[t].topics.length; q++) {
                        exams[i].modules[t].topics[q].questions.push(question);
                        topicIncrementor++;
                    }
                    topicIncrementor = 0;
                }
                    await exams[i].save();
            }
        }
    });
点赞