TypeError: moment().tz is not a function(TypeError: moment().tz 不是函数)
问题描述
使用 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');
//moment
而不是
const moment = require('moment-timezone');
//moment-timezone
另外,请确保您已经安装了 moment-timezone
Also, make sure you have installed moment-timezone with
npm install moment-timezone --save
使用 require('moment')
安装 moment,然后决定 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 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TypeError: moment().tz 不是函数


基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01