hexo-nexo主题配置中的问题

引子

好久没写博客了,一时间发现作者更新了新版本,我就很自然的,拉取最新版本,然后合并自己本地的博客源码,解决了好几个文件的冲突。看似是解决好了,不料在我 hexo cleanhexo g 操作时,出现了问题:

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
32
33
34
35
36
37
38
$ hexo g
ERROR Script load failed: themes\next\scripts\tags\exturl.js
Error: Cannot find module 'hexo-util'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (D:\myblog-hexo\node_modules\hexo\lib\hexo\index.js:213:21)
at D:\myblog-hexo\themes\next\scripts\tags\exturl.js:7:12
at D:\myblog-hexo\node_modules\hexo\lib\hexo\index.js:229:12
at tryCatcher (D:\myblog-hexo\node_modules\hexo\node_modules\bluebird\js\rel
ease\util.js:16:23)
at Promise._settlePromiseFromHandler (D:\myblog-hexo\node_modules\hexo\node_
modules\bluebird\js\release\promise.js:502:31)
at Promise._settlePromise (D:\myblog-hexo\node_modules\hexo\node_modules\blu
ebird\js\release\promise.js:559:18)
at Promise._settlePromise0 (D:\myblog-hexo\node_modules\hexo\node_modules\bl
uebird\js\release\promise.js:604:10)
at Promise._settlePromises (D:\myblog-hexo\node_modules\hexo\node_modules\bl
uebird\js\release\promise.js:683:18)
at Promise._fulfill (D:\myblog-hexo\node_modules\hexo\node_modules\bluebird\
js\release\promise.js:628:18)
at Promise._resolveCallback (D:\myblog-hexo\node_modules\hexo\node_modules\b
luebird\js\release\promise.js:423:57)
at Promise._settlePromiseFromHandler (D:\myblog-hexo\node_modules\hexo\node_
modules\bluebird\js\release\promise.js:514:17)
at Promise._settlePromise (D:\myblog-hexo\node_modules\hexo\node_modules\blu
ebird\js\release\promise.js:559:18)
at Promise._settlePromise0 (D:\myblog-hexo\node_modules\hexo\node_modules\bl
uebird\js\release\promise.js:604:10)
at Promise._settlePromises (D:\myblog-hexo\node_modules\hexo\node_modules\bl
uebird\js\release\promise.js:683:18)
at Promise._fulfill (D:\myblog-hexo\node_modules\hexo\node_modules\bluebird\
js\release\promise.js:628:18)
at D:\myblog-hexo\node_modules\hexo\node_modules\bluebird\js\release\nodebac
k.js:42:21
at D:\myblog-hexo\node_modules\hexo\node_modules\hexo-fs\node_modules\gracef
ul-fs\graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

虽然这些错误不影响正常使用,不过有点强迫症的我,是不能接受的。查了一下百度,并没有发现和我相同问题的,结果厚着脸到作者源码仓库 iissnan/hexo-theme-next,发布了一个ISS,求解错误,得到热心的同学解答,现把自己解决方法记录下来!

解决方案

首先,错误列表反复提示 Error: Cannot find module 'hexo-util' 这句,原来是加载 hexo-util 模块失败!
接下来,就安装此模块
命令行里打 npm install -- save-dev hexo-util 等待!、

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
> hexo-util@0.6.0 postinstall D:\myblog-hexo\node_modules\hexo-util
> npm run build:highlight


> hexo-util@0.6.0 build:highlight D:\myblog-hexo\node_modules\hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json

save-dev@2.0.0 node_modules\save-dev

hexo-util@0.6.0 node_modules\hexo-util
├── html-entities@1.2.0
├── striptags@2.2.1
├── bluebird@3.4.7
├── highlight.js@9.9.0
├── cross-spawn@4.0.2 (lru-cache@4.0.2, which@1.2.12)
└── camel-case@3.0.0 (upper-case@1.1.3, no-case@2.3.1)

显示为此,说明模块安装成功
再试 hexo cleanhexo g 等操作,都正常了。
总体来说,一般这些错误,都是模块的问题,知道了原理,再慢慢排查,就应该能解决相应的问题!~