Hexo执行报错 unknown block tag: xxxx

在执行Hexo命令时遇到的一个错误,在本地能够正常运行,备份完数据,从源码仓库克隆下来再运行报错,

尝试删除node_modules目录重新安装依赖并且清除npm缓存依然报错

image-20240624104918316

报错如下:

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
PS D:\Desktop\TestBlog\blog_source> hexo g
INFO Validating config
INFO Start processing
INFO hexo-blog-encrypt: encrypting "定制化代码生成项目-3.代码生成.md" based on the password configured in Front-matter with theme: default.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Nunjucks Error: _posts/Hexo基本使用.md [Line 841, Column 4] unknown block tag: galleryGroup
===== Context Dump =====
=== (line number probably different from source) ===
836 | <p>例如:</p>
837 | <!--code71-->
838 |
839 | <p><img src="https://img2023.cnblogs.com/blog/2233039/202404/2233039-20240410114020372-115062648.png" alt="image-20240410114016522"></p>
840 | <div class="gallery-group-main">
841 | {% galleryGroup '壁纸' '收藏的一些壁纸' '/gallery/wallpaper' https://img2023.cnblogs.com/blog/2233039/202403/2233039-20240301000822337-2125206689.jpg %}
842 | </div>
843 |
844 |
845 |
846 | <p>新建一个<code>.md</code>文件用于存放预览的图片,文件名称与目录中引用的路径名称一致,例如 <code>wallpaper.md</code></p>
===== Context Dump Ends =====
at formatNunjucksError (D:\Desktop\TestBlog\blog_source\node_modules\.store\hexo@7.2.0\node_modules\hexo\dist\extend\tag.js:145:15)
at D:\Desktop\TestBlog\blog_source\node_modules\.store\hexo@7.2.0\node_modules\hexo\dist\extend\tag.js:213:46
at tryCatcher (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\promise.js:725:18)
at _drainQueueStep (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\async.js:102:5)
at Async.drainQueues [as _onImmediate] (D:\Desktop\TestBlog\blog_source\node_modules\.store\bluebird@3.7.2\node_modules\bluebird\js\release\async.js:15:14)
at process.processImmediate (node:internal/timers:476:21)

从错误信息来看,问题出在 {% galleryGroup %} 标签上。

后来发现主题目录里没有文件,package.json中也没有引入实际使用的主题依赖,修改package.json文件,添加当前使用的主题依赖,重新安装依赖即可。

image-20240624110900465

或者重新在themes目录下载主题并安装依赖

image-20240624115132090

本地可以正常运行,使用GitHub Actions 自动部署时出现此错误,大概率是因为themes目录下的主题目录没有提交成功,可以手动git提交下,提交时一定进到主题目录内检查是否主题目录下的文件都提交了,出现此错误往往是只提交了个空目录,主题目录下没有文件造成的。

image-20241021144603105

参考文章

Hexo 关于 unknown block tag: cq