In a handful of places, I use moment.js to take various inputs and turn them into a moment object.
In some places I get the
"Moment Constructor Falls back to JS Date..."
warning that has been mentioned here so many times. I understand the problem, and the solution, but my question is how to identify which instance of the moment() usage is the problem.
Is there any reasonable way to track which instance is the problematic one?
Note: It's also possible that one of the JS libraries that I'm using is calling moment() in the problematic way - it's not necessarily in my code directly.
Add a hook:
moment.deprecationHandler = () => {debugger}
Or upgrade the warning to an error:
moment.deprecationHandler = (_,msg) => {throw new Error(msg)}
This seems to be somewhat undocumented. How to find this out? I see a stack trace in Chrome when I trip the warning:
> moment('20 Dec 2018')
global.js:293 Deprecation warning: value provided is not in a recognized […]
Error
at Function.createFromInputFallback (https://momentjs.com/static/js/global.js:320:98)
[…]
See what's inside that function:
> moment.createFromInputFallback
ƒ () {
if (hooks.deprecationHandler != null) {
hooks.deprecationHandler(null, msg);
}
if (firstTime) {
var args = [];
…
> moment.deprecationHandler
null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With