Hexo之错误分析

错误分析

如果你使用Hexo遇到同样的问题,这里有一些常见问题的解决方案。

YAML Parsing Error

1
2
JS-YAML: incomplete explicit mapping pair; a key node is missed at line 18, column 29:
last_updated: Last updated: %s
  1. 参数中包含冒号,请用加引号,如Last updated: %s
1
2
JS-YAML: bad indentation of a mapping entry at line 18, column 31:
last_updated:"Last updated: %s"
  1. 字段后面的冒号必须为英文冒号,如:last_updated:
  2. 字段冒号后面必须跟一个空格,如:last_updated: “Last updated: %s”

EMFILE Error

1
Error: EMFILE, too many open files

生成大量的文件时,可能遇到EMFILE错误。

可以运行以下命令来增加允许同步I / O操作的数量。

1
$ ulimit -n 10000

Process Out of Memory

hexo g时,遇到以下错误:

1
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

如下,更改hexo-cli文件的第一行,来增大nodejs堆内存.该bug已在新版本修复。

1
#!/usr/bin/env node --max_old_space_size=8192

Git Deployment Problems

  1. RPC failed
1
2
3
error: RPC failed; result=22, HTTP code = 403

fatal: 'username.github.io' does not appear to be a git repository

确保你有你的电脑上设置git正确或尝试使用HTTPS存储库URL。

  1. Error: ENOENT: no such file or directory

这个需要有一定的git的知识,因为可能是由于写错了标签,类别,或文件名,导致本地和github冲突了,Git不能自动合并这一变化所以它打破了自动分支。

解决办法:

  1. 检查文章的标签和类别,确保本地和github上是相同的。
  2. 合并分支(Commit)。
  3. 清除,重构。在站点目录下,命令行(即Git Bash)运行hexo cleanhexo g
  4. 手动将站点目录下的public文件夹复制到您的桌面
  5. 从你的master分支切换到部署在本地分支。
  6. 从桌面复制public文件夹到本地分支。
  7. 合并分支到github(Commit)。
  8. 切回master分支。

Server Problems

1
Error: listen EADDRINUSE

你可能使用相同的端口,同时开启了两个Hexo服务器。如果需要同时开启,可以尝试修改端口设置:

1
$ hexo server -p 5000

Plugin Installation Problems

1
npm ERR! node-waf configure build

这个错误可能发生在试图安装一个用Cc++或另一个javascript语言编写的插件。确保您已经安装了正确的编译器在您的计算机上。

Error with DTrace (Mac OS X)

1
2
3
{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

DTrace安装可能有问题,重装:

1
$ npm install hexo --no-optional

详见 #1326

Iterate Data Model on Jade or Swig

Hexo使用仓库的数据模型。这不是一个数组,所以你可能需要将对象转换为iterable。

1
2
{% for post in site.posts.toArray() %}
{% endfor %}

Data Not Updated

一些数据不能更新或新生成的文件的最后一个版本完全相同。清理缓存,再试一次:

1
$ hexo clean

No command is executed

那个不能使用除helpinitversion以外的命令行(即Git Bash)时, 有可能时站点目录下的 package.json文件,缺少hexo ,如下:

1
2
3
4
5
{
"hexo": {
"version": "3.2.2"
}
}

Escape Contents

Hexo使用Nunjucks渲染的页面. { { } }{ % % }将解析和可能会引起麻烦, 如果要在博文中出现,必须使用三引号:

1

Hello {{ sensitive }}

1
2


ENOSPC Error (Linux)

如果运行命令$ hexo server 返回一个错误:

1
Error: watch ENOSPC ...

可以通过运行$ npm dedupe或者以下命令行(即Git Bash):

1
$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

来增加测试时,你可以看见的文件数量。

EMPERM Error (Windows Subsystem for Linux)

如果在Windows Subsystem for Linux,运行命令$ hexo server 返回这个错误:

1
Error: watch /path/to/hexo/theme/ EMPERM

因为目前在Windows Subsystem for Linux中,有些内容更改时,还不能实时更新到hexo服务器。

所以需要重新编译,再启动服务器:

1
2
$ hexo generate
$ hexo server -s

Template render error

有时运行命令$ hexo generate 返回一个错误:

1
2
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path)

这意味着有些认不出来单词在你的文件,并且很可能在你的新博文,或者配置文件_config.yml中,比如缩进错误:

错误例子:

1
2
3
plugins:
hexo-generator-feed
hexo-generator-sitemap

###

如果本文对您有用,谢谢打赏。

TDsimon wechat
欢迎扫一扫上面的微信公众号,订阅我的博客!