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

于是升级 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

于是注释 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

接着 gitbook serve 就正常了~

reference

访客IP ,您的网络 访问优先

本站是个人博客,书写大数据、数据科学等领域的原创学习记录,转载请注明出处

本站运行于 腾讯云 腾讯云