gitbook: TypeError: cb.apply is not a function
今天运行 gitbook 有如下报错,原来是 node 的库找不到
~/gitbook/k8s$ gitbook
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
Referenced from: /usr/local/bin/node
Reason: image not found
Abort trap: 6
1
2
3
4
5
2
3
4
5
于是升级 npm,过程中会安装 node(这次安装是 15.7.0)
$ brew upgrade npm
1
接下来可以使用 gitbook 命令,但是无法 gitbook serve
~/gitbook/k8s$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287
if (cb) cb.apply(this, arguments)
^
TypeError: cb.apply is not a function
at /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
at FSReqCallback.oncomplete (fs.js:169:5)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
于是注释 polyfills.js 中的 3 行内容(62至64行)
diff /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js{,.bak}
62,64c62,64
< //fs.stat = statFix(fs.stat)
< //fs.fstat = statFix(fs.fstat)
< // fs.lstat = statFix(fs.lstat)
---
> fs.stat = statFix(fs.stat)
> fs.fstat = statFix(fs.fstat)
> fs.lstat = statFix(fs.lstat)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
接着 gitbook serve
就正常了~