TypeError: moment().tz is not a function

后端 未结 5 897
Happy的楠姐
Happy的楠姐 2021-01-01 08:26

When testing using jasmine, I am getting this error.

TypeError: moment.tz is not a function

My code that I try to test is

l         


        
5条回答
  •  借酒劲吻你
    2021-01-01 08:55

    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.

提交回复
热议问题