用hexo搭建了一个个人博客,最近在更新并上传到github之后发现上传的html文件都是空的,大小为0kb,本地的html文件也是空的,但是本地启动hexo server,访问http://localhost:4000 是正常的,在网上搜了不少解决方法,发现很多都解决不了问题,或者表述不清楚,踩了不少坑终于解决了,在这里记录一下。
1、踩坑历程
1.1 node版本升级
我的node版本是14.xxx,看网上有些说需要把node升级到稳定版本,于是执行以下命令1
2sudo npm i -g n
sudo n stable
此时发现node升级到了v16.15.1,删除原来的html文件重新生成,发现html还是空的1
2hexo clean
hexo generate
1.2 hexo debug
看有人说可以运行以下命令debug下看看有啥报错:1
hexo g --debug
运行之后发现有三个地方有提示:
- 报错1
1
2
3
4(node:37667) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:37667) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:37667) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
找了下解决方案说是在node_modules/stylus/lib/nodes/index.js文件头部添加以下内容,添加之后还是不行1
2
3exports.lineno = null;
exports.column = null;
exports.filename = null;
- 报错2
1
2
3Version 9 of Highlight.js has reached EOL and is no longer supported.
Please upgrade or ask whatever dependency you are using to upgrade.
https://github.com/highlightjs/highlight.js/issues/2877
把博客根目录下的package.json文件里的Highlight.js版本改为11.5.1,然后npm install,hexo重新生成还是不行
- 报错3
1
2
3
4
5
6
716:56:02.362 WARN ===============================================================
16:56:02.362 WARN ========================= ATTENTION! ==========================
16:56:02.362 WARN ===============================================================
16:56:02.362 WARN NexT repository is moving here: https://github.com/theme-next
16:56:02.363 WARN ===============================================================
16:56:02.363 WARN It's rebase to v6.0.0 and future maintenance will resume there
16:56:02.363 WARN ===============================================================
这个是hexo的NexT主题代码迁移提示,不升级暂时也没问题
1.3 正解:node版本降级
最后发现是node版本太高,hexo不支持,需要把node版本改为v12.xxx版本,注意不是大于v12就行,于是把node版本改为v12.22.12后解决问题。我用的是Mac,通过brew安装的node,于是执行以下命令重新安装node v12:1
2
3brew search node # 查找node可安装的版本,发现有node@12
brew uninstall node # 卸载原node
brew install node@12 # 安装新node
2、参考
解决hexo generate 生成的时候index.html为0kb空白的问题
hexo deploy上传github全是空白文件问题解决