鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ momentjs Deprecation Warning

momentjs Deprecation Warning

Moment.js運行時,刷新頁面后出現(xiàn)Moment Deprecation Warning

用moment對象代替Date()對象,用toDate()轉(zhuǎn)換成Date()對象,還是繼續(xù)有錯誤

報錯信息如下

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)

這樣問題應(yīng)該如何處理。

回答
編輯回答
萢萢糖

答案很明顯:你用的moment庫舊了,使用了一個過時方法moment().dates,最新是用moment().date。(2.16之前的版本)
解決方式: 升級Moment庫到最新版(目前2.22.2)
至于怎么升級,修改一下項目根目錄下的package.json,找到其中的moment,換上最新版本號

2017年7月17日 19:46