升级Node.js至8.0后hexo报错的解决

简介

本文介绍升级Node.js至8.0后使用hexo新建文章过程中报各种异常的解决方法.

遇到的问题

hexo新建文章时报一堆异常:

1
2
3
4
node_modules/dtrace-provider/build/Release/DTraceProviderBindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 57

这个DTraceProviderBindings.node一直报错,跟hexo-fs有关。

此外使用hexo clean --debug时能看到如下:

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
hexo git:(master) ✗ hexo clean --debug
14:07:03.119 DEBUG Hexo version: 3.3.8
14:07:03.122 DEBUG Working directory: ~/work/hexo/
14:07:03.243 DEBUG Config loaded: ~/work/hexo/_config.yml
14:07:03.486 DEBUG Plugin loaded: hexo-abbrlink
14:07:03.524 DEBUG Plugin loaded: hexo-util
14:07:03.792 DEBUG Plugin loaded: hexo-deployer-git
(node:25070) [DEP0061] DeprecationWarning: fs.SyncWriteStream is deprecated.
14:07:03.846 DEBUG Plugin loaded: hexo-algolia
14:07:03.851 DEBUG Plugin loaded: hexo-generator-archive
14:07:03.854 DEBUG Plugin loaded: hexo-generator-category
14:07:03.858 DEBUG Plugin loaded: hexo-generator-tag
14:07:03.862 DEBUG Plugin loaded: hexo-fs
14:07:03.867 DEBUG Plugin loaded: hexo-generator-index
14:07:03.873 DEBUG Plugin loaded: hexo-renderer-ejs
14:07:04.019 DEBUG Plugin loaded: hexo-server
14:07:04.020 DEBUG Plugin loaded: hexo-renderer-stylus
14:07:04.040 DEBUG Plugin loaded: hexo-renderer-marked
14:07:04.043 DEBUG Script loaded: themes/next/scripts/merge-configs.js
14:07:04.043 DEBUG Script loaded: themes/next/scripts/tags/button.js
14:07:04.078 DEBUG Script loaded: themes/next/scripts/tags/exturl.js
14:07:04.079 DEBUG Script loaded: themes/next/scripts/tags/center-quote.js
14:07:04.083 DEBUG Script loaded: themes/next/scripts/merge.js
14:07:04.083 DEBUG Script loaded: themes/next/scripts/tags/full-image.js
14:07:04.084 DEBUG Script loaded: themes/next/scripts/tags/label.js
14:07:04.084 DEBUG Script loaded: themes/next/scripts/tags/lazy-image.js
14:07:04.085 DEBUG Script loaded: themes/next/scripts/tags/note.js
14:07:04.085 DEBUG Script loaded: themes/next/scripts/tags/group-pictures.js
14:07:04.086 DEBUG Script loaded: themes/next/scripts/tags/tabs.js
14:07:04.088 INFO Deleted database.
14:07:04.090 DEBUG Database saved

可以看到hexo-deployer-git这个module用了一个废弃的方法.

问题的原因

原因是Node.js从6.0的版本升到8.10.0后,老的module不兼容了,我们只需要升级module就好了。

解决方法

参考http://yangbingdong.com/2017/build-blog-hexo-base/并没有解决问题。最终我的解决方法如下:

  1. 重装hexo-cli
    执行命令npm install hexo-cli -g安装最新版本的hexo-cli,版本为1.1.0.
  2. 之后使用hexo clean --debug观察出错的module,从https://www.npmjs.com/查到最新版本,然后修改至package.json即可,需要改的有:

    之后在博客根目录下执行npm update即可。最后通过hexo version可以查到对应版本:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    ➜ hexo git:(master) ✗ hexo version
    hexo: 3.3.8
    hexo-cli: 1.1.0
    os: Darwin 17.4.0 darwin x64
    http_parser: 2.7.0
    node: 8.10.0
    v8: 6.2.414.50
    uv: 1.19.1
    zlib: 1.2.11
    ares: 1.10.1-DEV
    modules: 57
    nghttp2: 1.25.0
    openssl: 1.0.2n
    icu: 60.1
    unicode: 10.0
    cldr: 32.0
    tz: 2017c

package.json如下:

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
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.3.8"
},
"dependencies": {
"gitment": "0.0.3",
"hexo": "^3.2.0",
"hexo-abbrlink": "^2.0.5",
"hexo-algolia": "^0.2.0",
"hexo-deployer-git": "^0.3.1",
"hexo-fs": "^0.2.3",
"hexo-generator-archive": "^0.1.4",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.0",
"hexo-generator-tag": "^0.2.0",
"hexo-renderer-ejs": "^0.3.1",
"hexo-renderer-marked": "^0.3.0",
"hexo-renderer-stylus": "^0.3.1",
"hexo-server": "^0.2.2",
"hexo-util": "^0.6.3"
}
}

显示 Gitment 评论