执行gitbook serve错误:
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287 if (cb) cb.apply(this, arguments) ^
执行gitbook serve过程:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... C:\Users\EB\AppData\Roaming\npm\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 C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18 at FSReqCallback.oncomplete (fs.js:169:5)
node
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ node -v v12.22.3
npm
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ npm -v 6.14.13
参考:
https://stackoverflow.com/questions/64211386/gitbook-cli-install-error-typeerror-cb-apply-is-not-a-function-inside-graceful
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.
按照上面的解释,只需要更新graceful-fs版本即可。
我的gitbook是global安装:npm install -g gitbook-cli
根据报错信息:
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
if (cb) cb.apply(this, arguments)
我切换到目录:
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\
执行命令:
EB@DESKTOP-K45IA6V MINGW64 ~/AppData/Roaming/npm/node_modules/gitbook-cli/node_modules/npm/node_modules $ npm install graceful-fs@latest --save npm notice created a lockfile as package-lock.json. You should commit this file. + graceful-fs@4.2.6 updated 1 package in 1.308s
更新成功(graceful-fs)。
再次尝试:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... info: 7 plugins are installed info: loading plugin "livereload"... OK info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 16 pages info: found 14 asset files _stream_readable.js:637 if (state.pipesCount === 1) { ^ TypeError: Cannot read property 'pipesCount' of undefined at ReadStream.Readable.pipe (_stream_readable.js:637:13) at C:\Users\EB\.gitbook\versions\3.2.3\node_modules\cpr\lib\index.js:163:22 at callback (C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:299:20) at FSReqCallback.oncomplete (fs.js:168:21)
参考:https://blog.csdn.net/test1280/article/details/118961808
降级nodejs版本为:node-v9.11.2-x64.msi
再次重试:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook init info: create SUMMARY.md info: initialization is finished EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... info: 7 plugins are installed info: loading plugin "livereload"... OK info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 16 pages info: found 14 asset files info: >> generation finished with success in 1.2s ! Starting server ... Serving book on http://localhost:4000
成功启动:
node-v14.17.3-x64.msi
gitbook init报错:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook init Installing GitBook 3.2.3 C:\Users\EB\AppData\Roaming\npm\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 C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18 at FSReqCallback.oncomplete (fs.js:193:5)
gitbook init报错(或):
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook init warn: no summary file in this book info: create README.md info: create SUMMARY.md TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise
node-v12.22.3-x64.msi
gitbook serve报错:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... C:\Users\EB\AppData\Roaming\npm\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 C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18 at FSReqCallback.oncomplete (fs.js:169:5)
更新graceful-fs,仍然报错:
EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook $ gitbook serve Live reload server started on port: 35729 Press CTRL+C to quit ... info: 7 plugins are installed info: loading plugin "livereload"... OK info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 16 pages info: found 14 asset files _stream_readable.js:637 if (state.pipesCount === 1) { ^ TypeError: Cannot read property 'pipesCount' of undefined at ReadStream.Readable.pipe (_stream_readable.js:637:13) at C:\Users\EB\.gitbook\versions\3.2.3\node_modules\cpr\lib\index.js:163:22 at callback (C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:299:20) at FSReqCallback.oncomplete (fs.js:168:21)
node-v9.11.2-x64.msi
成功。
https://blog.csdn.net/test1280/article/details/118961808