问题描述
执行 hexo generate 报错:
1 | TypeError: isDate is not a function |
排查过程
Phase 1: 根因定位
- 错误信息分析:错误发生在
hexo-front-matter包的front_matter.js文件中 - 代码分析:查看源码发现问题在第5行
1
var isDate = util.isDate;
- 环境确认:Node.js v24.14.0,hexo@3.8.0,hexo-front-matter@0.2.3
- 根因确认:
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 | widgets: |
最终结果
Hexo generate 成功生成 113 个文件
总结
- 主要问题:依赖包
hexo-front-matter使用了 Node.js 废弃的 API - 解决方案:升级 hexo 到 v5(v5 使用新版 hexo-front-matter 兼容新版 Node)
- 附带问题:升级后需确保主题配置完整