TypeError: date.format is not a function
-
just in case anyone else comes searching this forum for this error (cause nothing comes up at the moment). my forum died and this is the last of the log, and here is how i got it running again.
2023-03-05T05:35:17.631Z [4567/2688798] - warn: [emailer/send] User tøxic (uid: 766) is banned; not sending email due to system config. 2023-03-05T08:00:05.020Z [4567/2688798] - error: uncaughtException: date.format is not a function TypeError: date.format is not a function at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79) at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17) at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29) at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31) at Timeout.callbackWrapper [as _onTimeout] (/srv/mppc/forum/node_modules/cron/lib/job.js:171:11) at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7) {"date":"Sun Mar 05 2023 02:00:05 GMT-0600 (Central Standard Time)","error":{},"exception":true,"os":{"loadavg":[0.15,0.17,0.22],"uptime":728995.79},"process":{"argv":["/usr/bin/node","/srv/mppc/forum/app.js"],"cwd":"/srv/mppc/forum","execPath":"/usr/bin/node","gid":948,"memoryUsage":{"arrayBuffers":19507628,"external":21780480,"heapTotal":247558144,"heapUsed":193745224,"rss":413835264},"pid":2688798,"uid":951,"version":"v16.19.1"},"stack":"TypeError: date.format is not a function\n at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79)\n at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17)\n at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29)\n at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31)\n at Timeout.callbackWrapper [as _onTimeout] (/srv/mppc/forum/node_modules/cron/lib/job.js:171:11)\n at listOnTimeout (node:internal/timers:559:17)\n at processTimers (node:internal/timers:502:7)","trace":[{"column":79,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT._getNextDateFrom","line":271,"method":"_getNextDateFrom","native":false},{"column":17,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT.sendAt","line":185,"method":"sendAt","native":false},{"column":29,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT.getTimeout","line":202,"method":"getTimeout","native":false},{"column":31,"file":"/srv/mppc/forum/node_modules/cron/lib/job.js","function":"CJ.start","line":118,"method":"start","native":false},{"column":11,"file":"/srv/mppc/forum/node_modules/cron/lib/job.js","function":"Timeout.callbackWrapper [as _onTimeout]","line":171,"method":"callbackWrapper [as _onTimeout]","native":false},{"column":17,"file":"node:internal/timers","function":"listOnTimeout","line":559,"method":null,"native":false},{"column":7,"file":"node:internal/timers","function":"processTimers","line":502,"method":null,"native":false}]} 2023-03-05T08:00:05.022Z [4567/2688798] - error: TypeError: date.format is not a function at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79) at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17) at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29) at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31) at Timeout.callbackWrapper [as _onTimeout] (/srv/mppc/forum/node_modules/cron/lib/job.js:171:11) at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7) 2023-03-05T08:00:05.022Z [4567/2688798] - info: [app] Shutdown (SIGTERM/SIGINT) Initialised. 2023-03-05T08:00:05.034Z [4567/2688798] - info: [app] Web server closed to connections. 2023-03-05T08:00:05.065Z [4567/2688798] - info: [app] Live analytics saved. 2023-03-05T08:00:05.169Z [4567/2688798] - error: Encountered error pruning notifications MongoNotConnectedError: Client must be connected before running operations at executeOperationAsync (/srv/mppc/forum/node_modules/mongodb/lib/operations/execute_operation.js:24:19) at /srv/mppc/forum/node_modules/mongodb/lib/operations/execute_operation.js:12:45 at maybeCallback (/srv/mppc/forum/node_modules/mongodb/lib/utils.js:338:21) at executeOperation (/srv/mppc/forum/node_modules/mongodb/lib/operations/execute_operation.js:12:38) at FindCursor._initialize (/srv/mppc/forum/node_modules/mongodb/lib/cursor/find_cursor.js:54:50) at FindCursor.[kInit] (/srv/mppc/forum/node_modules/mongodb/lib/cursor/abstract_cursor.js:444:14) at next (/srv/mppc/forum/node_modules/mongodb/lib/cursor/abstract_cursor.js:512:22) at node:internal/util:364:7 at new Promise (<anonymous>) at next (node:internal/util:350:12) 2023-03-05T08:00:05.182Z [4567/2688798] - info: [app] Database connection closed. 2023-03-05T08:00:05.182Z [4567/2688798] - info: [app] Shutdown complete. [cluster] Child Process (2688798) has exited (code: 1, signal: null) [cluster] Spinning up another process... 2023-03-05T08:00:07.135Z [4567/3446164] - info: Initializing NodeBB v2.8.4 https://mpp.community/forum 2023-03-05T08:00:13.561Z [4567/3446164] - error: TypeError: date.format is not a function at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79) at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17) at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29) at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31) at new CJ (/srv/mppc/forum/node_modules/cron/lib/job.js:73:10) at module.exports (/srv/mppc/forum/src/posts/uploads.js:35:3) at Object.<anonymous> (/srv/mppc/forum/src/posts/index.js:28:21) at Module._compile (node:internal/modules/cjs/loader:1191:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10) at Module.load (node:internal/modules/cjs/loader:1069:32) [cluster] Child Process (3446164) has exited (code: 0, signal: null)
nodebb cli was broken too
$ ./nodebb upgrade Updating NodeBB... 1. Updating package.json file with defaults... OK 2. Bringing base dependencies up to date... started up to date, audited 1048 packages in 10s 86 packages are looking for funding run `npm fund` for details 18 vulnerabilities (4 moderate, 13 high, 1 critical) To address issues that do not require attention, run: npm audit fix To address all issues possible (including breaking changes), run: npm audit fix --force Some issues need review, and may require choosing a different dependency. Run `npm audit` for details. 3. Checking installed plugins for updates...Checking installed plugins and themes for updates... OK All packages up-to-date! 4. Updating NodeBB data store schema...Error occurred during upgrade: TypeError: date.format is not a function at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79) at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17) at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29) at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31) at new CJ (/srv/mppc/forum/node_modules/cron/lib/job.js:73:10) at module.exports (/srv/mppc/forum/src/posts/uploads.js:35:3) at Object.<anonymous> (/srv/mppc/forum/src/posts/index.js:28:21) at Module._compile (node:internal/modules/cjs/loader:1191:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10) at Module.load (node:internal/modules/cjs/loader:1069:32) 2023-03-05T19:01:49.057Z [4567/3609690] - error: uncaughtException: date.format is not a function TypeError: date.format is not a function at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79) at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17) at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29) at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31) at new CJ (/srv/mppc/forum/node_modules/cron/lib/job.js:73:10) at module.exports (/srv/mppc/forum/src/posts/uploads.js:35:3) at Object.<anonymous> (/srv/mppc/forum/src/posts/index.js:28:21) at Module._compile (node:internal/modules/cjs/loader:1191:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10) at Module.load (node:internal/modules/cjs/loader:1069:32) {"date":"Sun Mar 05 2023 13:01:49 GMT-0600 (Central Standard Time)","error":{},"exception":true,"os":{"loadavg":[0.32,0.28,0.27],"uptime":768699.83},"process":{"argv":["/usr/bin/node","/srv/mppc/forum/nodebb","upgrade"],"cwd":"/srv/mppc/forum","execPath":"/usr/bin/node","gid":948,"memoryUsage":{"arrayBuffers":18933897,"external":21053084,"heapTotal":68390912,"heapUsed":38620560,"rss":134238208},"pid":3609690,"uid":951,"version":"v16.19.1"},"stack":"TypeError: date.format is not a function\n at CT._getNextDateFrom (/srv/mppc/forum/node_modules/cron/lib/time.js:271:79)\n at CT.sendAt (/srv/mppc/forum/node_modules/cron/lib/time.js:185:17)\n at CT.getTimeout (/srv/mppc/forum/node_modules/cron/lib/time.js:202:29)\n at CJ.start (/srv/mppc/forum/node_modules/cron/lib/job.js:118:31)\n at new CJ (/srv/mppc/forum/node_modules/cron/lib/job.js:73:10)\n at module.exports (/srv/mppc/forum/src/posts/uploads.js:35:3)\n at Object.<anonymous> (/srv/mppc/forum/src/posts/index.js:28:21)\n at Module._compile (node:internal/modules/cjs/loader:1191:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)\n at Module.load (node:internal/modules/cjs/loader:1069:32)","trace":[{"column":79,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT._getNextDateFrom","line":271,"method":"_getNextDateFrom","native":false},{"column":17,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT.sendAt","line":185,"method":"sendAt","native":false},{"column":29,"file":"/srv/mppc/forum/node_modules/cron/lib/time.js","function":"CT.getTimeout","line":202,"method":"getTimeout","native":false},{"column":31,"file":"/srv/mppc/forum/node_modules/cron/lib/job.js","function":"CJ.start","line":118,"method":"start","native":false},{"column":10,"file":"/srv/mppc/forum/node_modules/cron/lib/job.js","function":"new CJ","line":73,"method":null,"native":false},{"column":3,"file":"/srv/mppc/forum/src/posts/uploads.js","function":"module.exports","line":35,"method":"exports","native":false},{"column":21,"file":"/srv/mppc/forum/src/posts/index.js","function":null,"line":28,"method":null,"native":false},{"column":14,"file":"node:internal/modules/cjs/loader","function":"Module._compile","line":1191,"method":"_compile","native":false},{"column":10,"file":"node:internal/modules/cjs/loader","function":"Module._extensions..js","line":1245,"method":".js","native":false},{"column":32,"file":"node:internal/modules/cjs/loader","function":"Module.load","line":1069,"method":"load","native":false}]}
so I found out there is a weird bug in node-cron that nobody knows how to fix, https://github.com/kelektiv/node-cron/issues/636 (for a bug in the error code) https://github.com/kelektiv/node-cron/issues/467 (for the bug that triggers the error).
To get the forum working again open up ./src/posts/uploads.js and comment out this unimportant code that triggers the bug.
Ultimately I guess we have to wait for devs to figure it out
-
@baris oh fixed as of four hours ago https://github.com/kelektiv/node-cron/pull/639. but this was after your comment https://github.com/kelektiv/node-cron/issues/636#issuecomment-1455103644 about the fix for the error message, not the cause of the error.
funny how they're suddenly getting this months-old pr merged, cause the daylight savings time starting on march 12 is breaking everything. That cron's next run time is right at the moment time changes forward!
Also, I did try installing the master branch but it did not work, cause as I just realized the nodebb upgrade script immediately reverted it.
-
-
-
@isbl said in TypeError: date.format is not a function:
Another workaround is to just change the string to something like "0 5 * * 0" so that it isn't close to the DST switchover.
Thanks,
my production and testing forums were both down today due to this bug and I used your fix. -
-
-