node-cron - 弃用警告:imediateStart 已弃用并将被删除

node-cron - Deprecation warning: imediateStart is deprecated and will be removed

我将 nodejs 从 8 更新到 10.12 并收到该警告消息。

D:\BitBucket\EA Studio>node index
DEPRECIATION: imediateStart is deprecated and will be removed soon in favor of the options param.
...

package.json

{
  "dependencies": {
    ...
    "node-cron": "^2.0.3",
}

用法:

"use strict";

const cron = require("node-cron");
cron.schedule("5 * * * *", () => null, false);

有什么解决办法吗?

由于我的代码中没有使用imediateStart,所以警告来源必须在node-cron 的内部代码中。开发人员这样做是为了不忘记更新自己的代码吗?显示多少会更好:"This version of node-cron uses deprecated code. Please update it to version xxx as soon as it is released".

运行 带有 --trace-warnings 标志的脚本。例如:node --trace-warnings index.js。它将为您提供导致警告的详细信息。

只需更换

cron.schedule("5 * * * *", () => null, false);

cron.schedule("5 * * * *", () => null, {scheduled:false});

来自 node-cron 关于 schedule 方法的文档:

options Object: Optional configuration for job scheduling.

Options

scheduled: A boolean to set if the created task is schaduled. Default true;

timezone: The timezone that is used for job scheduling;