Gitbook-cli install error TypeError: cb.apply is not a function inside graceful-fs
Asked Answered
S

10

29

When executing any gitbook command in the terminal, the following error is thrown:

/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

The gitbook-cli seems to not be working right now, failing because of their outdated graceful-fs dependency.

Any ideas how to fix this?

Smithery answered 5/10, 2020 at 15:12 Comment(1)
I was able to set my node version to v12.18.2 and get the gitbook-cli to work. This is a "good enough" solution for me, until the following issue is addressed: github.com/GitbookIO/gitbook-cli/issues/110Centipoise
S
65

The issue was originally a problem inside graceful-fs but they solved it in this commit I believe.

The problem is that GitBook is still using outdated dependencies that pull in versions of graceful-fs without the fix.

The solution I found was to update graceful-fs inside gitbook like this:

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. 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. It should have fixed the installing problem.

Smithery answered 5/10, 2020 at 15:12 Comment(8)
that's really useful answer.Unwelcome
this is very useful in my macbookCabinda
For those not using macOs find your global npm installation path using npm root -g .Taiga
This solution worked like a charm for me. For those who have installed node using nvm, the path may be different. I was able to find the location of gitbook via which gitbookCircumnavigate
This seems to not work anymore with the latest version of graceful-fs. Gitbook just exits silently after any command. Version [email protected] seems to work.Finish
Sorry, but this ecosystem is so broken. I still see TypeError: cb.apply is not a function with [email protected]Tulatulip
@KirillTaran solution worked for me! This also worked for me (install another version): npm install [email protected] --globalAmarillo
The latest module for graceful-fs didn't work for me. The below did: cd /opt/homebrew/lib/node_modules/gitbook-cli/node_modules/npm/node_modules; npm install [email protected] --saveDecree
P
20

TL;DR

Why not switch to honkit(Fork of GitBook)?


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.

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.

Pouched answered 20/5, 2021 at 11:35 Comment(3)
makes total sense, that's actually what I've done, I've switched to docusaurus. Although this could have been a comment instead of a full answer.Smithery
I've liked to read this struct as a viable alternative to the gitbook problem, trying honkit outWickerwork
if you love book making, another choice is dartbook, completely compatible with gitbook project but implemented in Dart, and run more fast than gitbook and honkitChalybeate
S
13

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:

_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 ...

Subcontract answered 22/1, 2021 at 7:12 Comment(3)
I got a different error (TypeError: Cannot set property 'readableListening' of undefined for internal/streams/readable.js:864 state.readableListening = this.listenerCount('readable') > 0;) when installing the katex plugin but this solution helped me fix it nevertheless.Sterner
@Sterner were you able to solve this error?Wickner
@alireza Yes, despite starting from a different error, this answer helped to resolve it. All I did was downgrading graceful-fs to 4.2.0.Sterner
S
7

Just replace the crashing file polyfills.js with this one: https://raw.githubusercontent.com/isaacs/node-graceful-fs/168bdb8f0bb3174e8499d4bc5878deead4172c39/polyfills.js

This works like a charm in Node.js v16.13.0.

Sooth answered 21/11, 2021 at 21:44 Comment(0)
C
3

@Chalist 's Solution also was not working for me. So, I did this :

  1. npm uninstall gitbook-cli -g
  2. nvm install 10
  3. nvm use 10
  4. npm install gitbook-cli -g

Now all gitbook commands like gitbook serve will work fine.

Civilization answered 26/1, 2023 at 17:39 Comment(0)
B
1

Full instructions for WSL2

Install 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

check versions and install node --version npm --version

install 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;

cd /home/<USER_NAME>/.nvm/versions/node/v14.17.1/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/ npm install [email protected] --save

Then cd to your git document folder gitbook install gitbook serve

Broach answered 23/6, 2021 at 23:4 Comment(0)
A
1

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.

Use this https://github.com/nvm-sh/nvm.

Abject answered 13/2, 2022 at 16:23 Comment(0)
A
1

for those who are very busy and have no time to debug:

  1. install an older version of gitbook:
 npm install [email protected] --global
  1. modify this file: vim ~/.gitbook/versions/3.2.3/lib/output/website/copyPluginAssets.js, Replace all confirm: true to
confirm: false
  1. gitbook serve

then everything goes well.

My Env:

  • ubuntu 20.04 LTS ( windows WSL)
  • node 16
Alkanet answered 5/6, 2022 at 1:13 Comment(0)
U
1

I changed the Node version to 12 with nvm and works fine.

Udder answered 16/6, 2022 at 23:59 Comment(0)
F
1

My working solution on macOS Sonoma 14.2.1 (23C71)

Testing

  • gitbook init
  • gitbook serve

This constellation is working now nicely

Fishery answered 16/1 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.