惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
博客园_首页
S
SegmentFault 最新的问题
H
Help Net Security
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
量子位
GbyAI
GbyAI
M
MIT News - Artificial intelligence
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
B
Blog
月光博客
月光博客
博客园 - 聂微东
Vercel News
Vercel News
罗磊的独立博客
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
L
Lohrmann on Cybersecurity
I
Intezer
小众软件
小众软件
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
C
Check Point Blog
AWS News Blog
AWS News Blog
C
Cisco Blogs
Martin Fowler
Martin Fowler
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
宝玉的分享
宝玉的分享
S
Security Affairs
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hacker News: Front Page
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog

Anran758's blog

Promise 与异步编程 数据结构实践 MySQL 实践 组件通信: EventBus 的原理解析与应用 Redux 食用指南 计算机网络原理笔记 Accessibility Parsing 无障碍页面分析 软件工程笔记 JavaScript 实现二叉树 闭包与链式设计的使用示例 React 知识回顾 (优化篇) React 知识回顾 (使用篇) React vs Vue webpack + Travis CI 自动部署项目应用 从零构建 webpack 脚手架(基础篇) Flexbox 布局实际用例 Flexbox 布局入门 Hexo blog 的升级与同步方案 将 JSON 数据格式输出至页面上
Hexo 常见问题解决方案
本文作者: anran758 · 2020-09-27 · via Anran758's blog

记录 Hexo 升级或使用时遇到的问题和一些解决方案。

TypeError: config._d.getTime is not a function

经过排查,本次发生错误是由 hexo-related-popular-posts 引发,在该库源码中使用 moment 初始化 list.date 导致了错误。 list.date 通过打印值可以看到是一个 moment 对象,但这个 moment 对象并不规范或者说可能在某处修改了这个 moment 对象的值。

moment 内部初始化有一段逻辑是:

1
this._d = new Date(config._d != null ? config._d.getTime() : NaN);

这个 config 就是 moment(list.date) 传入的 list.date 的值。config._d 是一个时间类型的字符串,并不是 Date 类型,因此没有 getTime 的方法。

临时解决方法有两种,一是将 theme/next/_config.yml 中的 related_posts.params.isDate 设为 false,也就是推荐列表中不展示时间。

二是修改源码,做一层错误处理。从 node_modules 中打开文件(\node_modules\hexo-related-popular-posts\lib\list-json.js), 在编辑器中查找以下代码:

1
2
3
if (inOptions.isDate && list.date != '') {
ret.date = moment(list.date).format(config.date_format || 'YYYY-MM-DD')
}

修改为:

1
2
3
4
5
6
7
if (inOptions.isDate && list.date != '') {
try {
ret.date = moment(list.date).format(config.date_format || 'YYYY-MM-DD')
} catch(ex) {
ret.date = moment(list.date._d).format(config.date_format || 'YYYY-MM-DD')
}
}

上述只是临时的解决方案,由于不好确定是哪一方的原因,也不想继续耗费太多精力在上面。

错误日志如下,以供参考:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Unhandled rejection Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk) [Line 19, Column 14]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_partials\head\head-unique.njk) [Line 10, Column 23]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk) [Line 3, Column 3]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_partials\header\index.njk) [Line 6, Column 15]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_partials\header\sub-menu.njk) [Line 2, Column 29]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_partials\header\sub-menu.njk)
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk) [Line 5, Column 3]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\post.njk) [Line 9, Column 12]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_macro\post.njk) [Line 214, Column 16]
Template render error: (C:\Users\user\Desktop\project\blog\themes\next\layout\_partials\post\post-related.njk)
TypeError: config._d.getTime is not a function
at Object._prettifyError (C:\Users\user\Desktop\project\blog\node_modules\nunjucks\src\lib.js:36:11)
at C:\Users\user\Desktop\project\blog\node_modules\nunjucks\src\environment.js:561:19
at Template.root [as rootRenderFunc] (eval at _compile (C:\Users\user\Desktop\project\blog\node_modules\nunjucks\src\environment.js:631:18), <anonymous>:45:3)
at Template.render (C:\Users\user\Desktop\project\blog\node_modules\nunjucks\src\environment.js:550:10)
at C:\Users\user\Desktop\project\blog\themes\next\scripts\renderer.js:35:29
at _View._compiled.locals [as _compiled] (C:\Users\user\Desktop\project\blog\node_modules\hexo\lib\theme\view.js:136:50)
at _View.render (C:\Users\user\Desktop\project\blog\node_modules\hexo\lib\theme\view.js:39:17)
at C:\Users\user\Desktop\project\blog\node_modules\hexo\lib\hexo\index.js:64:21
at tryCatcher (C:\Users\user\Desktop\project\blog\node_modules\bluebird\js\release\util.js:16:23)
at C:\Users\user\Desktop\project\blog\node_modules\bluebird\js\release\method.js:15:34
at RouteStream._read (C:\Users\user\Desktop\project\blog\node_modules\hexo\lib\hexo\router.js:47:5)
at RouteStream.Readable.read (_stream_readable.js:470:10)
at resume_ (_stream_readable.js:949:12)
at process._tickCallback (internal/process/next_tick.js:63:19)