momentjs Deprecation Warning

发布于 2022-09-07 20:08:09 字数 2252 浏览 15 评论 0

Moment.js运行时,刷新页面后出现Moment Deprecation Warning

用moment对象代替Date()对象,用toDate()转换成Date()对象,还是继续有错误

报错信息如下

Deprecation warning: dates accessor is deprecated. Use date instead.
Arguments: 
Error
    at Moment.dates (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/moment/moment.js:320:98)
    at eval (eval at compile (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:549:12), <anonymous>:61:39)
    at returnedFn (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:580:17)
    at tryHandleCache (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:223:34)
    at View.exports.renderFile [as engine] (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/ejs/lib/ejs.js:437:10)
    at View.render (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/view.js:135:8)
    at tryRender (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/application.js:640:10)
    at Function.render (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/response.js:1008:7)
    at /Users/ephraimguo/Documents/OST_work/booking_Prototype/routes/index.js:248:18
    at Layer.handle [as handle_request] (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/layer.js:95:5)
    at /Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Users/ephraimguo/Documents/OST_work/booking_Prototype/node_modules/express/lib/router/index.js:335:12)

这样问题应该如何处理。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你再特殊 2022-09-14 20:08:09

答案很明显:你用的moment库旧了,使用了一个过时方法moment().dates,最新是用moment().date。(2.16之前的版本)
解决方式: 升级Moment库到最新版(目前2.22.2)
至于怎么升级,修改一下项目根目录下的package.json,找到其中的moment,换上最新版本号

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文