gitbook出现TypeError: cb.apply is not a function解决办法
JS

gitbook出现TypeError: cb.apply is not a function解决办法

admin
2020-12-23 / 0 评论 / 368 阅读 / 正在检测是否收录...

执行gitbook serve的时候出现如下错误

> fastmock-doc@1.0.0 serve /Users/gongminghua/Public/03private/fastmock-docs
> 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)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fastmock-doc@1.0.0 serve: `gitbook serve`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fastmock-doc@1.0.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gongminghua/.npm/_logs/2020-12-23T02_00_45_660Z-debug.log

 按照提示中的路径,/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js 打开polyfills.js文件,找到这个函数

function statFix (orig) {
  if (!orig) return orig
  // Older versions of Node erroneously returned signed integers for
  // uid + gid.
  return function (target, cb) {
    return orig.call(fs, target, function (er, stats) {
      if (!stats) return cb.apply(this, arguments)
      if (stats.uid < 0) stats.uid += 0x100000000
      if (stats.gid < 0) stats.gid += 0x100000000
      if (cb) cb.apply(this, arguments)
    })
  }
}

在第62-64行调用了这个函数

fs.stat = statFix(fs.stat)
fs.fstat = statFix(fs.fstat)
fs.lstat = statFix(fs.lstat)

把这三行代码注释掉就解决报错了

0

评论 (0)

取消