Sometimes, we want to fix TypeError: moment().tz is not a function with JavaScript.
In this article, we’ll look at how to fix TypeError: moment().tz is not a function with JavaScript.
How to fix TypeError: moment().tz is not a function with JavaScript?
To fix TypeError: moment().tz is not a function with JavaScript, we should make sure that we’re importing moment-timezone
before referencing tz
.
We install moment-timezone
by running
npm install moment-timezone --save
Then, we write
const moment = require('moment-timezone');
to import the moment-timezone
module in our code.
Conclusion
To fix TypeError: moment().tz is not a function with JavaScript, we should make sure that we’re importing moment-timezone
before referencing tz
.