Disclaimer: This article will be updated from time to time to add new content or make any changes in exsisting sections without any notice. Using them under your own investigation in production is advised.
I. Installation
1. The Mismatched graceful-fs dependency
Since gitbook has been abandoned for quite a long time, it’s a mess to install gitbook from scratch for someone who has to keep using it. The most common problem that they would definitely face is the mismatched graceful-fs dependency. When you clone some gitbook from github, the first thing to do is to install gitbook dependencies.
1
2
3
4
gitbook install
# or just try to display gitbook versiongitbook -V
With no doubt, graceful-fs would be the one reported causing a problem.
1
2
3
4
5
6
7
8
9
10
11
12
info: installing 4 plugins using npm@3.9.2
info:
info: installing plugin "image-captions"info: install plugin "image-captions"(*) from NPM with version 3.1.0
loadCurrentTree ▄ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
/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 (node:fs:195:5)
However, the root cause of problem lies on that a mismatched version of graceful-fs is used as a dependency and no one is there to fix gitbook. For most environments, updating graceful-fs to the latest version will do the fix.
1
2
3
4
5
# go to gitbook dependency foldercd /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/
# update gitbook to latest versionnpm install graceful-fs@latest --save
Unluckily, if some specific plugins might not be compatible with the latest version of graceful-fs.
info: installing 4 plugins using npm@3.9.2
info:
info: installing plugin "image-captions"info: install plugin "image-captions"(*) from NPM with version 3.1.0
loadCurrentTree ▄ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
node:internal/streams/readable:879
state.readableListening = this.listenerCount('readable') > 0;
^
TypeError: Cannot set property 'readableListening' of undefined
at ReadStream.Readable.on (node:internal/streams/readable:879:29) at untarStream (/Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/lib/fetch-package-metadata.js:304:8) at addShrinkwrap (/Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/lib/fetch-package-metadata.js:200:3) at /Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/lib/fetch-package-metadata.js:185:14
at /Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/node_modules/iferr/index.js:13:50
at RES (/Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/node_modules/inflight/inflight.js:23:14) at f (/Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/node_modules/once/once.js:17:25) at /Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/lib/cache.js:362:16
at /Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/node_modules/write-file-atomic/index.js:29:9
at LOOP (/Users/fakeUser/.gitbook/versions/3.2.3/node_modules/npm/node_modules/slide/lib/chain.js:7:26)