(node:6868) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated 警告:`node --inspect --debug-brk`已被弃用。

5

这是我第一次遇到这样的错误,如果我没有注意到任何重要因素,请原谅我。 运行代码时,我得到的完整错误如下:

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

如下所示:

enter image description here

它还突出显示了这行代码:
return new Script(code, options);

如下所示:

enter image description here

这是我使用 nvm 显示的 node.js 版本。
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,它们显示在文件目录中:

enter image description here

这里更改了各种设置,并设置了将在后续使用的变量:

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),如下所示:

enter image description here

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;

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

enter image description here

我相信这个错误与弃用的问题无关,尽管我认为最好提一下。虽然我认为我可以绕过这个问题,但长远来看,我认为这是不可接受的,如果有人能提供解决这个问题的解决方案,或者只是指引我正确的方向,那将不胜感激。
(此外,以防万一,以下是 server.js (https://hastebin.com/ibuweyaxes.js) 和 seed.js (https://hastebin.com/ibuweyaxes.js) 的完整代码链接。)另外,由于我对此事了解不足,我可能会包含一些无用的内容或未能包含有用的内容。

1
在 package.json 中,不要指定要安装的包的特定版本("express": "^4.15.4"),尝试将版本替换为 latest,如 "express": "latest",然后安装这些包。我不确定它是否有效,但值得一试。 - kgangadhar
@kganghar 我什么都没改,因为我已经拥有最新的一切,但是将来知道这个信息很有用,谢谢。 - Jonathan Woollett-light
1个回答

1
问题出在Seed.js文件的第343行,正如错误信息所指出的那样,你不能在异步函数外使用await。虽然SeedDB可能是一个异步函数,但是await代码实际上位于then catch语句内部,必须将then声明为异步函数才能避免错误。
来自pastebin的原始代码片段如下:
}).then(() => {

所以只需像下面我所做的那样,在then之前添加async关键字。

}).then(async () => {

And here's it in the full Promise:

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();
            }
        }
    });


1
不可否认,这只会导致更多错误,但这些是我自己造成的错误,至少这解决了我混乱中的一些问题,谢谢。 - Jonathan Woollett-light

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接