question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: date.format is not a function

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

We have a NestJS application which uses @nestjs/schedule, version 2.1.0. For deployment we use Docker images. For almost all of our deployments it works just fine. One of the client reported though, that on their onprem, the app stopped with the following error:

","stream":"stdout","time":"2022-09-08T09:37:15.496090995Z"} {"log":"/root/app/node_modules/cron/lib/time.js:271
","stream":"stderr","time":"2022-09-21T20:19:45.716126382Z"} {"log":"							Time Zone: ${zone || '\"\"'} - Cron String: ${this} - UTC offset: ${date.format(
","stream":"stderr","time":"2022-09-21T20:19:45.716202505Z"} {"log":"							 ^
","stream":"stderr","time":"2022-09-21T20:19:45.71621206Z"} {"log":"
","stream":"stderr","time":"2022-09-21T20:19:45.716218529Z"} {"log":"TypeError: date.format is not a function
","stream":"stderr","time":"2022-09-21T20:19:45.716224284Z"} {"log":" at CT._getNextDateFrom (/root/app/node_modules/cron/lib/time.js:271:79)
","stream":"stderr","time":"2022-09-21T20:19:45.716230014Z"} {"log":" at CT.sendAt (/root/app/node_modules/cron/lib/time.js:185:17)
","stream":"stderr","time":"2022-09-21T20:19:45.716245614Z"} {"log":" at CT.getTimeout (/root/app/node_modules/cron/lib/time.js:202:29)
","stream":"stderr","time":"2022-09-21T20:19:45.716251935Z"} {"log":" at CJ.start (/root/app/node_modules/cron/lib/job.js:118:31)
","stream":"stderr","time":"2022-09-21T20:19:45.716257787Z"} {"log":" at Timeout.callbackWrapper [as _onTimeout] (/root/app/node_modules/cron/lib/job.js:171:11)
","stream":"stderr","time":"2022-09-21T20:19:45.716270449Z"} {"log":" at listOnTimeout (node:internal/timers:559:17)
","stream":"stderr","time":"2022-09-21T20:19:45.716276992Z"} {"log":" at processTimers (node:internal/timers:502:7)
","stream":"stderr","time":"2022-09-21T20:19:45.71628273Z"} {"log":"npm notice 
","stream":"stderr","time":"2022-09-21T20:19:45.793334096Z"} {"log":"npm notice New minor version of npm available! 8.15.0 -> 8.19.1
","stream":"stderr","time":"2022-09-21T20:19:45.79369313Z"} {"log":"npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.19.1>
","stream":"stderr","time":"2022-09-21T20:19:45.794002242Z"} {"log":"npm notice Run `npm install -g npm@8.19.1` to update!
","stream":"stderr","time":"2022-09-21T20:19:45.794012227Z"} {"log":"npm notice 
","stream":"stderr","time":"2022-09-21T20:19:45.794136382Z"}

We have multiple @Cron annotations in our codebase, but all looks the same:

@Cron(CronExpression.EVERY_5_SECONDS, { name: DEVICE_REGISTRATION_CRON_NAME })
async exampleCron(): Promise<void> {
  this.schedulerRegistry.getCronJob(DEVICE_REGISTRATION_CRON_NAME).stop();
  try {
    // ... code that may fail, and we must not run other iteration till it finishes
  } finally {
    this.schedulerRegistry.getCronJob(DEVICE_REGISTRATION_CRON_NAME).start();
  }
}

I searched for this error, and found some similar at https://github.com/kelektiv/node-cron/issues, but those are not same, but I would say, very similar, and relates to the same bug.

What can I do? What the NestJS team will do?

Minimum reproduction code

Steps to reproduce

No response

Expected behavior

I would expect even if the cron fails, it would not stop the whole application.

Package version

2.1.0

NestJS version

9.0.0

Node.js version

16

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crypto-jianyongcommented, Oct 17, 2022
0reactions
kamilmysliwieccommented, Oct 24, 2022

Please report this issue in this repository https://github.com/kelektiv/node-cron

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript date.format is not a function - Stack Overflow
I am using this piece of code to get string representing date yyyy-mm-dd from a hidden ...
Read more >
TypeError: date.format is not a function in JavaScript
The "date.format is not a function" error occurs because the format method is not implemented in JavaScript. To solve the error, use a...
Read more >
TypeError: date.format is not a function #2440 - GitHub
How to reproduce: Select any date. Clear input field. Click on it to open date picker. date is "" in this case.
Read more >
TypeError: Undefined in not a function - date format
In Var end, I need to had this: . tz("Europe/Lisbon"). format("DD/MM/YYYY"). When I had, I get TypeError: Undefined in not a function.
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
Maybe there is a typo in the function name? Maybe the object you are calling the method on does not have this function?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found