0%

Hexo 升级 Node 版本

起因

电脑重装系统 重新装的新的Node,无法使用Hexo

配置环境

  • Node v12.18
  • Git

node 设置环境变量

重装Node的时候最好卸载掉旧版本文件,防止冲突

npm更换淘宝镜像

1
npm config set registry https://registry.npm.taobao.org

npm 安装 grunt-cli hexo

安装 grunt-cli

1
npm install -g grunt-cli

安装 hexo

1
npm install -g hexo

查看信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ hexo -v
hexo-cli: 3.1.0
os: Windows_NT 10.0.18363 win32 x64
node: 12.18.0
v8: 7.8.279.23-node.37
uv: 1.37.0
zlib: 1.2.11
brotli: 1.0.7
ares: 1.16.0
modules: 72
nghttp2: 1.41.0
napi: 6
llhttp: 2.0.4
http_parser: 2.9.3
openssl: 1.1.1g
cldr: 37.0
icu: 67.1
tz: 2019c
unicode: 13.0

升级错误记录

node 升级14 以后,hexo 部署失败了

报错如下

1
2
3
4
5
6
7
8
9
10
11
12
13
$ hexo d
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
at copyFile (fs.js:1924:10)
at tryCatcher (E:\projects\hexo\rcantblog_hexo\blog\node_modules\hexo-fs\node_modules\bluebird\js\release\util.js:16:23)
at ret (eval at makeNodePromisifiedEval (C:\Users\cqs\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
at E:\projects\hexo\rcantblog_hexo\blog\node_modules\hexo-fs\lib\fs.js:144:39
at tryCatcher (E:\projects\hexo\rcantblog_hexo\blog\node_modules\hexo-fs\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (E:\projects\hexo\rcantblog_hexo\blog\node_modules\hexo-fs\node_modules\bluebird\js\release\promise.js:517:31)
at Promise._settlePromise (E:\projects\hexo\rcantblog_hexo\blog\node_modules\hexo-fs\node_modules\bluebird\js\release\promise.js:574:18)

google了下发现是hexo不支持最新node14+,issue见此,解决方案两种:降低node版本或者升级最新[email protected]+。

我尝试了升级hexo到4.2.1发现并没有什么卵用,照样报相同的错,所以选择了降低node版本到稳定版:

直接到官网下载最新稳定版:https://nodejs.org/en/download/

然后重新执行 hexo clean && hexo deploy 打包命令就好了。

P.S. 如果打包成功后,最好验证下hexo下的分类和标签是否正常工作,我就遇到了点击自己博客首页的「分类」和「标签」后,跳转的页面报404,原因是打开的路由最后多了个空格:./categories/%20 。不知道啥原因,所以我把hexo版本退回到了3.8.0。这样路由就正确了。

Hexo 升级5.4 2021/3/20

打开package.json 修改 dependencies 项:

1
"hexo": "^5.4.0"

更新

1
2
3
4
5
6
7
8
9
10
11
$ npm update
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ [email protected]
added 7 packages from 12 contributors, removed 17 packages and updated 8 packages in 18.609s

22 packages are looking for funding
run `npm fund` for details

Hexo博客系列

欢迎关注我的其它发布渠道