TypeError: Cannot read property 'execute' of undefined
See original GitHub issueHere is my code, simple test to try and get it to console out every minute to make sure the schedule will work. also tried with rule.minute = (next minute of the hour); and rule.minute = 0;
console.log('Inside Delete Processor');
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
//rule.hour = 0;
rule.minute = null;
var deleteSchedule = schedule.scheduleJob(rule, deleteExpiredFiles());
function deleteExpiredFiles(){
console.log(moment().format('MMM DD, Y hh:mm:ss A'), ': Scheduled Tick');
}
Received same error every time.
C:\NodeCode\Processor\node_modules\node-schedule\lib\schedule.js:177
this.job.execute();
^
TypeError: Cannot read property 'execute' of undefined
at Job.invoke (C:\NodeCode\Processor\node_modules\node-schedule\lib\schedule.js:177:13)
at Timeout._onTimeout (C:\NodeCode\Processor\node_modules\node-schedule\lib\schedule.js:479:11)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top Results From Across the Web
Cannot read property 'execute' of undefined Discord Bot js ...
The reasoning for the is when calling command.execute() you are attempting to call a function named 'execute' in the command's module. Since you ......
Read more >cannot read property 'execute' of undefined” (JavaScript, Node ...
It generally means that at the point of execution, the variable/object holding the property cannot be found by the script. It may be...
Read more >Getting the same error (Cannot read property 'execute ... - Reddit
The error message means that client.commands.get('ping') is returning undefined, so it doesn't have an execute method to invoke.
Read more >[Solved]-How do I fix the error "Cannot read property 'execute ...
Coding example for the question How do I fix the error "Cannot read property 'execute' of undefined"?-discord.js.
Read more >Cannot read property 'execute' of undefined #556 - GitHub
I have one little problem with my code; My code: commands.js module.exports.execute= { name: 'commands', description: "Embed!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @PsyTae,
You should not invoke the function, but pass the
Function
object:In:
you are invoking the function
deleteExpiredFiles
bydeleteExpiredFiles()
.deleteExpiredFiles
does not have any return statement (i.e. the return value isundefined
).Thus your line is equivalent to:
which is further equivalent to:
scheduleJob
expects at least 2 proper arguments to actually create aJob
. Otherwise it returnsnull
.When writing anonymous functions you are less likely to invoke it by mistake.
vs
Please close the issue if this solves your problem.
Sorry to reply to this closed issue, but how would I pass an argument to the named function?
I’m currently doing
schedule.scheduleJob(new Date(), function() { myNamedFunction(myArgument) });