【问题标题】:(node:6868) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated(node:6868) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` 已弃用
【发布时间】:2018-02-11 09:07:41
【问题描述】:

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

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

如下图:

它还突出显示了这行代码:

return new Script(code, options);

如下图:

这是我正在运行的 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,它们显示在继承文件目录中:

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

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

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;

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

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

(也以防万一,这里有指向hastebin中server.jshttps://hastebin.com/ibuweyaxes.js)和seed.jshttps://hastebin.com/ibuweyaxes.js)的完整代码的链接) 另外请注意,由于我对这件事缺乏了解,我很可能要么包含了无用的东西,要么没有包含有用的东西。

【问题讨论】:

  • 在 package.json 中而不是指定要安装的包的特定版本("express": "^4.15.4")尝试用latest 替换版本,如"express": "latest" 并安装包。我不确定它是否有效,但值得一试。
  • @kganghar 没有改变任何东西,因为我有最新的东西,但以后知道会很有用,谢谢。

标签: javascript node.js mongodb express mongoose


【解决方案1】:

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

从您的 pastebin 中截取的原始代码如下所示:

}).then(() => {

所以只需在 then 中的箭头函数之前添加异步,就像我在下面所做的那样。

}).then(async () => {

这是完整的 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();
            }
        }
    });

【讨论】:

  • 诚然,这只会导致更多错误,但我自己做的错误,这至少解决了我的烂摊子,谢谢。
猜你喜欢
  • 1970-01-01
  • 2017-11-28
  • 2021-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-24
  • 1970-01-01
  • 2020-02-01
相关资源
最近更新 更多