Hexo 使用七牛云同步插件 hexo-qiniu-sync 出错

阿里云产品限时红包,最高 ¥1888 元,立即领取

安装完 hexo-qiniu-sync 插件,运行出现以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
INFO  Now start qiniu sync.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:488:13)
at sync (/Users/lfy/ihaowu/node_modules/hexo-qiniu-sync/sync.js:110:26)
at Object.sync (/Users/lfy/ihaowu/node_modules/hexo-qiniu-sync/sync.js:113:13)
at Function.commands.sync (/Users/lfy/ihaowu/node_modules/hexo-qiniu-sync/cmd.js:28:14)
at Hexo.<anonymous> (/Users/lfy/ihaowu/node_modules/hexo-qiniu-sync/index.js:122:11)
at Hexo.tryCatcher (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Hexo.ret (eval at <anonymous> (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39)
at /Users/lfy/ihaowu/node_modules/hexo/lib/hexo/index.js:192:9
at tryCatcher (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promise.js:480:31)
at new Promise (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promise.js:70:37)
at Hexo.call (/Users/lfy/ihaowu/node_modules/hexo/lib/hexo/index.js:188:10)
at runHexoCommand (/usr/local/lib/node_modules/hexo/node_modules/hexo-cli/lib/index.js:58:17)
at tryCatcher (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/lfy/ihaowu/node_modules/hexo/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:367:17)

找到关键的部分:

1
2
3
TypeError: Arguments to path.join must be strings
at Object.posix.join (path.js:488:13)
at sync (/Users/lfy/ihaowu/node_modules/hexo-qiniu-sync/sync.js:110:26)

查看源代码中的 sync.js,发现其中的 sync() 方法:

1
2
3
4
5
6
7
8
9
10
for(file in files) {
var fname = path.join(local_dir, dir, files[i]); // 这部分出错
var stat = fs.lstatSync(fname);
if(stat.isDirectory() == true) {
sync(path.join(dir, files[i]));
} else {
var name = path.join(dirPrefix, fname.replace(local_dir, '')).replace(/\\/g, '/').replace(/^\//g, '');
check_upload(fname,name);
}
}

上面注释部分似乎是传递的参数类型出错了。

查看了官方最新的代码,发现确实不一样。于是将上面的内容替换成下面:

1
2
3
4
5
6
7
8
9
10
files.forEach(function(file)  {
var fname = path.join(local_dir + '', dir + '', file + '');
var stat = fs.lstatSync(fname);
if(stat.isDirectory() == true) {
sync(path.join(dir + '', file + ''));
} else {
var name = path.join(dirPrefix, fname.replace(local_dir, '')).replace(/\\/g, '/').replace(/^\//g, '');
check_upload(fname,name);
}
})

问题解决了。