Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

javascript - TypeError: moment().tz is not a function

When testing using jasmine, I am getting this error.

TypeError: moment.tz is not a function

My code that I try to test is

let myDate = moment().tz(undefined, vm.timeZone).format('YYYY-MM-DD'); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Fix

If you're using Node.js, you may accidentally be using

const moment = require('moment'); //moment

instead of

const moment = require('moment-timezone'); //moment-timezone

Also, make sure you have installed moment-timezone with

npm install moment-timezone --save

Explanation

The bug of requiring moment without timezones could occur by installing moment with require('moment'), later deciding to npm install moment-timezone, and then forgetting to update the require.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...