[英]Gitbook-cli install error TypeError: cb.apply is not a function inside graceful-fs
When executing any gitbook
command in the terminal, the following error is thrown:在终端中执行任意
gitbook
命令时,抛出如下错误:
/home/travis/.nvm/versions/node/v12.18.3/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 /home/travis/.nvm/versions/node/v12.18.3/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
at FSReqCallback.oncomplete (fs.js:169:5)
NOTE: This does not happen in node version v12.18.2 and is still happening in version v14.6.0注意:这不会发生在节点版本 v12.18.2 中,并且仍然发生在版本 v14.6.0 中
The gitbook-cli
seems to not be working right now, failing because of their outdated graceful-fs
dependency. gitbook-cli
现在似乎无法正常工作,因为它们过时graceful-fs
依赖性而失败。
Any ideas how to fix this?任何想法如何解决这一问题?
The issue was originally a problem inside graceful-fs
but they solved it in this commit I believe.这个问题最初是
graceful-fs
内部的一个问题,但我相信他们在这个提交中解决了它。
The problem is that GitBook is still using outdated dependencies that pull in versions of graceful-fs without the fix.问题是 GitBook 仍在使用过时的依赖项,这些依赖项在没有修复的情况下引入了优雅的 fs 版本。
The solution I found was to update graceful-fs
inside gitbook like this:我找到的解决方案是像这样更新 gitbook 中的
graceful-fs
:
If you've installed gitbook globally by doing npm install -g gitbook-cli
then your path in macOS should be something like /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules
.如果您通过执行
npm install -g gitbook-cli
全局npm install -g gitbook-cli
那么您在 macOS 中的路径应该类似于/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules
。 Your path may differ depending on your OS or installation location.您的路径可能因您的操作系统或安装位置而异。
Run this:运行这个:
cd /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/
npm install graceful-fs@latest --save
Then try installing GitBook.然后尝试安装 GitBook。 It should have fixed the installing problem.
它应该已经解决了安装问题。
The last solution was great , but when I use npm install graceful-fs@latest --save
in the right place and then rerun gitbook build
, I got the following error:最后一个解决方案很棒,但是当我在正确的位置使用
npm install graceful-fs@latest --save
然后重新运行gitbook build
,出现以下错误:
_stream_readable.js:545
switch (state.pipesCount) {
^
TypeError: Cannot read property 'pipesCount' of undefined
at module.exports.Readable.pipe (_stream_readable.js:545:16)
at module.exports.ZipArchiveOutputStream._smartStream (/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:184:11)
at module.exports.ZipArchiveOutputStream._appendStream (/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js:96:20)
at module.exports.ArchiveOutputStream.entry (/node_modules/compress-commons/lib/archivers/archive-output-stream.js:88:10)
at module.exports.ZipStream.entry (/node_modules/zip-stream/index.js:138:49)
at Zip.append (/node_modules/archiver/lib/plugins/zip.js:53:15)
at Archiver._moduleAppend (/node_modules/archiver/lib/core.js:172:16)
at Archiver._onQueueTask (/node_modules/archiver/lib/core.js:370:8)
at /node_modules/async/dist/async.js:3879:9
And ... guess what , when I change the version of graceful-fs to 4.2.0
, it all worked ...而且……猜猜怎么着,当我
change the version of graceful-fs to 4.2.0
,一切都奏效了……
TL;DR TL; 博士
Why not switch to honkit (Fork of GitBook)?为什么不切换到honkit ( GitBook 的Fork)?
The "why" for switching:切换的“为什么”:
I knew this is not the answer to the question, but I would like to mention that the repository of gitbook has been deprecated 3 years ago, this makes it a bad choice for usage and especially security.我知道这不是问题的答案,但我想提一下,gitbook 的存储库在 3 年前已被弃用,这使其成为使用特别是安全性的糟糕选择。
So I searched for the alternatives, and I found mdBook and honkit , turned out that honkit has good compatibility with gitbook, maybe switch to honkit is a better choice instead of fixing a 3 years old software with some hacking.于是我寻找替代方案,我找到了mdBook和honkit ,结果证明honkit与 gitbook 有很好的兼容性,也许切换到honkit是更好的选择,而不是用一些黑客来修复一个 3 岁的旧软件。
Just replace the crashing file polyfills.js
with this one: https://raw.githubusercontent.com/isaacs/node-graceful-fs/168bdb8f0bb3174e8499d4bc5878deead4172c39/polyfills.js只需用以下文件替换崩溃文件
polyfills.js
:https://raw.githubusercontent.com/isaacs/node-graceful-fs/168bdb8f0bb3174e8499d4bc5878deead4172c39/polyfills.js
This works like a charm in Node.js v16.13.0.这在 Node.js v16.13.0 中非常有用。
Full instructions for WSL2 WSL2 的完整说明
Install nvm curl -o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh |安装 nvm curl -o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash close WSL bash shell and re-open nvm install --lts
bash 关闭 WSL bash shell 并重新打开 nvm install --lts
check versions and install node --version npm --version检查版本并安装node --version npm --version
install gitbook-cli npm install -g gitbook-cli安装 gitbook-cli npm install -g gitbook-cli
Any gitbook command gives error gitbook build TypeError: Cannot set property 'readableListening' of undefined for internal/streams/readable.js:864 state.readableListening = this.listenerCount('readable') > 0;任何 gitbook 命令都会给出错误gitbook build TypeError: Cannot set property 'readableListening' of undefined for internal/streams/readable.js:864 state.readableListening = this.listenerCount('readable') > 0;
cd /home/<USER_NAME>/.nvm/versions/node/v14.17.1/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/ npm install graceful-fs@4.2.0 --save cd /home/<USER_NAME>/.nvm/versions/node/v14.17.1/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/ npm install graceful-fs@4.2.0 --save
Then cd to your git document folder gitbook install gitbook serve然后cd到你的git文档文件夹gitbook install gitbook serve
You can update package-lock.json
> gitbook-cli
> npm
> graceful-fs
to something like:您可以将
package-lock.json
> gitbook-cli
> npm
> graceful-fs
为:
"graceful-fs": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==",
"dev": true
},
This worked for me:这对我有用:
npm install graceful-fs@latest --save
Then re-run:然后重新运行:
npm install -g gitbook-cli
UPDATE ===== Another option would be to use NVM and install node v12.8.2.更新 ===== 另一种选择是使用 NVM 并安装节点 v12.8.2。
Use this https://github.com/nvm-sh/nvm .使用这个https://github.com/nvm-sh/nvm 。
for those who are very busy and have no time to debug:对于那些很忙没有时间调试的人:
npm install gitbook-cli@2.1.2 --global
vim ~/.gitbook/versions/3.2.3/lib/output/website/copyPluginAssets.js
, Replace all confirm: true
tovim ~/.gitbook/versions/3.2.3/lib/output/website/copyPluginAssets.js
,全部替换confirm: true
为confirm: false
gitbook serve
then everything goes well.然后一切顺利。
My Env:我的环境:
I changed the Node version to 12
with nvm and works fine.我使用 nvm 将 Node 版本更改为
12
,并且工作正常。
Reinstall the graceful-fs
and gitbook-cli
packages to fix the issue,重新安装
graceful-fs
和gitbook-cli
包来解决这个问题,
Open a terminal on the project root folder.在项目根文件夹上打开一个终端。
Execute the following commands in your terminal.在终端中执行以下命令。
npm install graceful-fs@latest --save npm install -g gitbook-cli
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.