TypeError:moment()。tz不是函数 [英] TypeError: moment().tz is not a function
问题描述
使用jasmine进行测试时,我收到此错误。
When testing using jasmine, I am getting this error.
TypeError:moment.tz不是函数
我尝试测试的代码是
let myDate = moment().tz(undefined, vm.timeZone).format('YYYY-MM-DD');
推荐答案
修复
如果你正在使用Node.js,你可能会意外地使用
Fix
If you're using Node.js, you may accidentally be using
const moment = require('moment');
// 时刻
而不是
const moment = require('moment-timezone');
// moment-timezone
另外,请确保已安装了时刻 -
Also, make sure you have installed moment-timezone with
npm install moment-timezone --save
通过 require安装时刻可能会出现需要时间而没有时区的错误( '时刻')
,后来决定 npm install moment-timezone
,然后忘记更新 require
。
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
.
这篇关于TypeError:moment()。tz不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!