hexo指令错误修复记录

最近不知道为什么,反正只要终端执行 hexo 命令,都会报一个莫名奇妙的错误,但是又不影响程序的运行。作为一名强迫症患者,实在无法忍受,经过无数次实验,最终将此问题进行解决。

此错误如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ Error: Cannot find module './build/Release/DTraceProviderBindings'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/hexo-cli/node_modules/dtrace-provider/dtrace-provider.js:18:23)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/hexo-cli/node_modules/bunyan/lib/bunyan.js:79:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32) code: 'MODULE_NOT_FOUND' }

具体的意思应该是什么模块找不到,我试了网上各种办法,什么重装 hexo,安装简洁版的 hexo,将 npm 镜像换成淘宝镜像,hexo 重装不知道多少次还是报同样的错误,但是他报错就报错,又不影响程序运行,就很奇怪。搞得我快疯了,最后我没办法了,根据异常,找到出错的文件:/usr/local/lib/node_modules/hexo-cli/node_modules/dtrace-provider/dtrace-provider.js。定位到如下的代码:

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
for (var i in builds) {
try {
var binding = require('./build/' + builds[i] + '/DTraceProviderBindings');
DTraceProvider = binding.DTraceProvider;
break;
} catch (e) {
if (err === null) {
err = e;
}
}
}

if (!DTraceProvider) {
/*
* If the platform looks like it _should_ have DTrace
* available, log a failure to load the bindings.
*/
if (process.platform === 'darwin' ||
process.platform === 'sunos' ||
process.platform === 'freebsd') {
console.error(err);
}

DTraceProvider = DTraceProviderStub;
}

这个异常不就是从这里 console 打印的出来的吗?我把你注释掉,眼不见心不烦,反正你又不影响程序运行,注释如下代码:

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
// for (var i in builds) {
// try {
// var binding = require('./build/' + builds[i] + '/DTraceProviderBindings');
// DTraceProvider = binding.DTraceProvider;
// break;
// } catch (e) {
// if (err === null) {
// err = e;
// }
// }
// }

if (!DTraceProvider) {
/*
* If the platform looks like it _should_ have DTrace
* available, log a failure to load the bindings.
*/
if (process.platform === 'darwin' ||
process.platform === 'sunos' ||
process.platform === 'freebsd') {
// console.error(err);
}

DTraceProvider = DTraceProviderStub;
}

然后随便运行一个 hexo 指令,发现错误确实没有了~ 终于治好了我的强迫症~

文章目录
,
粤ICP备17147440号