Hexo常见错误总结

本人在搭建Hexo博客的过程中,遇到了一些问题,通过百度,google等手段,加上自己的理解,进行了问题的复现和解决,现在总结成以下几点,希望可以帮助到一些人。

Hexo使用常见错误一:

问题描述:Template render error: (unknown path)

Hexo站点目录下的source/_post目录中如果没有任何Markdown文档时,在使用 hexo s 命令启动Hexo进行前台预览时,会报以下错误:

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
[root@Hexo-Blog-Server blog]# hexo s
INFO Start processing
INFO Generating Baidu urls for last 100 posts
INFO Posts urls generated in baidu_urls.txt

FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Template render error: (unknown path) [Line 8, Column 25]
Error: Unable to call `the return value of (posts["first"])["updated"]["toISOString"]`, which is undefined or falsey
at Object._prettifyError (/root/blog/node_modules/nunjucks/src/lib.js:36:11)
at /root/blog/node_modules/nunjucks/src/environment.js:567:19
at Template.root [as rootRenderFunc] (eval at _compile (/root/blog/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:235:3)
at Template.render (/root/blog/node_modules/nunjucks/src/environment.js:556:10)
at Hexo.module.exports (/root/blog/node_modules/hexo-generator-feed/lib/generator.js:41:24)
at Hexo.tryCatcher (/root/blog/node_modules/bluebird/js/release/util.js:16:23)
at Hexo.<anonymous> (/root/blog/node_modules/bluebird/js/release/method.js:15:34)
at /root/blog/node_modules/hexo/lib/hexo/index.js:318:20
at tryCatcher (/root/blog/node_modules/bluebird/js/release/util.js:16:23)
at MappingPromiseArray._promiseFulfilled (/root/blog/node_modules/bluebird/js/release/map.js:61:38)
at MappingPromiseArray.PromiseArray._iterate (/root/blog/node_modules/bluebird/js/release/promise_array.js:114:31)
at MappingPromiseArray.init (/root/blog/node_modules/bluebird/js/release/promise_array.js:78:10)
at MappingPromiseArray._asyncInit (/root/blog/node_modules/bluebird/js/release/map.js:30:10)
at _drainQueueStep (/root/blog/node_modules/bluebird/js/release/async.js:142:12)
at _drainQueue (/root/blog/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/root/blog/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/root/blog/node_modules/bluebird/js/release/async.js:17:14)
at processImmediate (internal/timers.js:439:21)

解决方法:

查看是否安装了hexo-generator-feed插件,执行以下命令:

1
2
3
[root@Hexo-Blog-Server blog]# npm list hexo-generator-feed
hexo-site@0.0.0 /root/blog
└── hexo-generator-feed@2.0.0

方法一:Hexo站点目录下的source/_post目录中添加文章

Hexo站点目录下的source/_post目录中不能一片文章都没有,可以使用 hexo new <title> 命令创建新文章,也可以使用Markdown编辑器编写好文章之后上传到source/_post目录中,这样再执行 hexo s 命令启动Hexo进行前台预览时,就不会报错了。

方法二:卸载 hexo-generator-feed 插件

执行以下命令,卸载Hexo的 hexo-generator-feed 插件

注:不建议使用此方法

1
# npm uninstall hexo-generator-feed

卸载完成后,再执行 hexo s 命令启动Hexo进行前台预览时,就不会报错了。

Hexo使用常见错误二:

问题描述:Cannot read property ‘count’ of undefined

使用 Hexo server 启动Hexo服务进行预览的时候,报如下所示错误:

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
32
33
34
35
36
[root@Hexo-Blog-Server blog]# hexo s
INFO Start processing
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
config.translate_title==> undefined
config.url==> https://linuxops.fun
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'count' of undefined
at Hexo.module.exports (/root/blog/node_modules/hexo-baidu-url-submit/lib/generator.js:4:41)
at Hexo.tryCatcher (/root/blog/node_modules/bluebird/js/release/util.js:16:23)
at Hexo.<anonymous> (/root/blog/node_modules/bluebird/js/release/method.js:15:34)
at /root/blog/node_modules/hexo/lib/hexo/index.js:318:20
at tryCatcher (/root/blog/node_modules/bluebird/js/release/util.js:16:23)
at MappingPromiseArray._promiseFulfilled (/root/blog/node_modules/bluebird/js/release/map.js:61:38)
at MappingPromiseArray.PromiseArray._iterate (/root/blog/node_modules/bluebird/js/release/promise_array.js:114:31)
at MappingPromiseArray.init (/root/blog/node_modules/bluebird/js/release/promise_array.js:78:10)
at MappingPromiseArray._asyncInit (/root/blog/node_modules/bluebird/js/release/map.js:30:10)
at _drainQueueStep (/root/blog/node_modules/bluebird/js/release/async.js:142:12)
at _drainQueue (/root/blog/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/root/blog/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/root/blog/node_modules/bluebird/js/release/async.js:17:14)
at processImmediate (internal/timers.js:439:21)

解决方法:

查看是否安装了hexo-baidu-url-submit插件,执行以下命令:

1
2
3
[root@Hexo-Blog-Server blog]# npm list hexo-baidu-url-submit          
hexo-site@0.0.0 /root/blog
└── hexo-baidu-url-submit@0.0.6

如上所示,显示Hexo站点中安装了hexo-baidu-url-submit插件,可通过一下两种方法解决这个问题。

方法一:卸载hexo-baidu-url-submit依赖包

1
# npm uninstall hexo-baidu-url-submit --save

然后再执行 Hexo server 启动Hexo服务进行预览,就不回去报错了。

方法二:在Hexo站点配置文件_config.yml中增加以下配置

1
2
3
4
5
6
# baidu site Collection
baidu_url_submit:
count: 100 # 提交最新的一个链接
host: # 填写博客域名,在百度站长平台中注册的域名
token: # 请注意这是您的秘钥, 所以请不要把博客源代码发布在公众仓库里!
path: baidu_urls.txt # 文本文档的地址, 新链接会保存在此文本文档里

然后再执行 Hexo server 启动Hexo服务进行预览,就不回去报错了。

Hexo使用常见错误三:

问题描述:ERROR Deployer not found: git

使用 hexo d 命令将Hexo站点下 .deploy_git 目录下的静态页面发布到远程仓库时,报如下所示错误:

1
2
[root@Hexo-Blog-Server blog]# hexo d                      
ERROR Deployer not found: git

解决方法

使用git进行发布时,需要安装0 hexo-deployer-git 插件。执行以下命令进行安装。

1
# npm install hexo-deployer-git --save

安装完成后,在Hexo的站点配置文件_config.yml中增加以下配置

1
2
3
4
5
6
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: git
repository: git@***.github.com:***/***.github.io.git
branch: master

注:Hexo 3.0 以上部署类型不再是github,而是 git

Hexo使用常见错误四:

问题描述:Unhandled rejection TypeError: Cannot set property ‘lastIndex’ of undefined

使用 hexo d 发布静态页时,报如下所示错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Unhandled rejection TypeError: Cannot set property 'lastIndex' of undefined
at highlight (/Users/leesin/Desktop/blog/node_modules/highlight.js/lib/highlight.js:511:35)
at /Users/leesin/Desktop/blog/node_modules/highlight.js/lib/highlight.js:561:21
at Array.forEach (<anonymous>)
at Object.highlightAuto (/Users/leesin/Desktop/blog/node_modules/highlight.js/lib/highlight.js:560:40)
at /Users/leesin/Desktop/blog/node_modules/hexo-util/lib/highlight.js:117:25
at highlight (/Users/leesin/Desktop/blog/node_modules/hexo-util/lib/highlight.js:120:7)
at highlightUtil (/Users/leesin/Desktop/blog/node_modules/hexo-util/lib/highlight.js:22:14)
at /Users/leesin/Desktop/blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:62:15
at String.replace (<anonymous>)
at Hexo.backtickCodeBlock (/Users/leesin/Desktop/blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:14:31)
at Hexo.tryCatcher (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/util.js:16:23)
at Hexo.<anonymous> (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/method.js:15:34)
at Promise.each.filter (/Users/leesin/Desktop/blog/node_modules/hexo/lib/extend/filter.js:63:65)
at tryCatcher (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/util.js:16:23)
at Object.gotValue (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/reduce.js:155:18)
at Object.gotAccum (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/reduce.js:144:25)
at Object.tryCatcher (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/promise.js:606:10)
at _drainQueueStep (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/async.js:142:12)
at _drainQueue (/Users/leesin/Desktop/blog/node_modules/bluebird/js/release/async.js:131:9)

解决方法:

将Hexo站点配置文件_config.yml中的 auto_detect设置为false ,如下所示:

1
auto_detect: false