Nodejs node-schedule npm 抛出错误“this.job.execute is not a function”

aim*_*man 5 javascript node.js npm express

我是 nodejs 的新手,我编写了一个 nodejs 程序并使用 node-schedule 每分钟调度一次。但是在运行一段时间并在控制台生成几个日志后,nodejs 抛出错误this.job.execute is not a function

这是我正在使用的代码:

var nodeSchedule = require('node-schedule');

runJob();

function runJob(){
    console.log("start");
    nodeSchedule.scheduleJob('0 * * * * *',require('./prodModules.js'));

}
Run Code Online (Sandbox Code Playgroud)

我得到的日志是:

C:\Users\1060641\Downloads\NodeJS HealthReport\Collector>node src\main\nodejs\collector_main.js
start
Connected
Ready
logged in as Super User
nfs_check running...
NFS Check completed
snapchart_check running...
C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:177
    this.job.execute();
             ^

TypeError: this.job.execute is not a function
    at Job.invoke (C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:177:14)
    at null._onTimeout (C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:445:11)
    at Timer.listOnTimeout (timers.js:92:15)

C:\Users\1060641\Downloads\NodeJS HealthReport\Collector>
Run Code Online (Sandbox Code Playgroud)

我不认为我有什么问题,prodModules.js因为它独立运行它运行良好。调度正在抛出错误。

请帮忙。

小智 2

尝试重新导入“node-schedule”,我使用新的导入运行了您的代码,并且它按预期工作。

要在 Windows cmd 上向下导入:> npm install node-schedule