Hexo generate 报错排查

Posted by Forgus on 2026-03-09

问题描述

执行 hexo generate 报错:

1
2
TypeError: isDate is not a function
at parse (/root/projects/blog/node_modules/hexo-front-matter/lib/front_matter.js:70:9)

排查过程

Phase 1: 根因定位

  1. 错误信息分析:错误发生在 hexo-front-matter 包的 front_matter.js 文件中
  2. 代码分析:查看源码发现问题在第5行
    1
    var isDate = util.isDate;
  3. 环境确认:Node.js v24.14.0,hexo@3.8.0,hexo-front-matter@0.2.3
  4. 根因确认util.isDate 是 Node.js 废弃的 API,在 Node.js 22 中已完全移除

Phase 2: 升级 Hexo

执行 npm install hexo@5 --save 升级到 hexo v5

Phase 3: 新问题

升级后出现新错误:

1
Cannot read properties of undefined (reading 'forEach')

发生在 themes/beantech/layout/_partial/sidebar.ejs:9

Phase 4: 修复主题配置

问题原因:主题配置文件缺少 widgets 配置

解决方案:在 themes/beantech/_config.yml 中添加:

1
2
widgets:
- search

最终结果

Hexo generate 成功生成 113 个文件

总结

  • 主要问题:依赖包 hexo-front-matter 使用了 Node.js 废弃的 API
  • 解决方案:升级 hexo 到 v5(v5 使用新版 hexo-front-matter 兼容新版 Node)
  • 附带问题:升级后需确保主题配置完整