Tag Archives: gitbook

[Solved] gitbook: node_modules\npm\node_modules\graceful-fs\polyfills.js:287

gitbook:node_modules\npm\node_modules\graceful-fs\polyfills.js:287


1. Exception
Error executing 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)
                 ^

Execute the gitbook serve procedure:

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)

2. Environment

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

 


3. Solution
My gitbook is installed globally: npm install -g gitbook-cli
According to the error message.
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)
I switch to the catalog.
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\
Execute the command:

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.
+ [email protected]
updated 1 package in 1.308s

Update succeeded (graceful FS).

Try again:

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)

Still report an error!

Final solution:

reference resources: https://blog.csdn.net/test1280/article/details/118961808

Downgrade nodejs version to: node-v9.11.2-x64.msi

Try again:

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

Successfully started:


5. Postscript

5.1.case1

node-v14.17.3-x64.msi

Gitbook init error:

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 error (or):

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

5.2.case2

node-v12.22.3-x64.msi

gitbook server error:

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)

Update graceful FS and still report an error:

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)

5.3. Case 3

Node-v9.11.2-x64.msi

Russian.

Typeerror in gitbook init: cb.apply is not a function solution

The following error occurred when executing gitbook init:

Find the prompt path, open the polyfills.js file, and find this function

This function is called on lines 65-67

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

Comment out the three lines of code to solve the problem

Because of the NPM version problem, you can refer to the following two methods to solve. However, we must pay attention to which polyfills.js has a problem, which is explained in detail in the error prompt.

Recommended reading:
1 https://blog.csdn.net/yq_ forever/article/details/112121742
https://www.cnblogs.com/cyxroot/p/13754475.html

Error: enoent: no such file or directory, stat

The gitbook project can’t run when you open it on another computer. Both gitbook serve and gitbook build report errors.

Error: ENOENT: no such file or directory, stat ‘C:\Users\Lenovo\www\mdspg\md\mybook_ book\gitbook\gitbook-plugin-fontsettings\ fontsettings.js ’

it turned out to be a bug (vision: 3.2.3).

The solution is as follows.

The following file was found in the user directory.
.gitbook\versions\3.2.3\lib\output\website\ copyPluginAssets.js

Replace all

confirm: true

with

confirm: false

Error: enoent: no such file or directory, stat ‘/ usr / local / var / www / /_ book/gitbook/git

Every time a gitbook is edited, there will be an error that causes the service that has been started through gitbook serve to stop. The error message is: error: enoent: no such file or directory, stat ‘/ usr/local/var/www//_ book/gitbook/gitbook-plugin-livereload/ plugin.js ‘

The background is that a new gitbook has been installed. Every time I edit the MD file in the project, I will hold the above error. As a result, the service I started through gitbook serve will stop and I can’t browse the edited gitbook normally

At the beginning, I didn’t care when I reported the error. The back office revised and edited the file several times, and found that the gitbook service would stop and report the above error after each modification. I found that this was not a mistake in my operation, but a problem with gitbok. After looking for the problem for a while, I didn’t have any idea, so I Baidu found out the bug in gitbook itself, The original configuration of gitbook is wrong. The specific modification method is as follows:

1. Find the configuration file address of gitbook (MAC system) in the user directory: Cd ~ to jump to the user directory of the current user

2. Find ~ /. Gitbook/versions/3.2.3/lib/output/website/ copyPluginAssets.js File, and then find all the confirm configuration items in this file (a total of 2 places), and change the original value of true to false

confirm: false

There are two places in total. Just change them

Error: enoent: no such file or directory, stat ‘/ usr / local / var / www / / book/gitbook/git

After gitbook every edit, there will be an Error, which will cause the service started by gitbook Serve to stop. The Error message is :gitbook edit Error: Error: ENOENT: no such file or directory, stat ‘/usr/local/var/www/… /_book/gitbook/gitbook-plugin-livereload/plugin.js’
In the background, a gitbook was newly installed. Every time I edited the MD file in the project, I would catch the above error, which caused me to stop the service started by Gitbook Serve and could not properly browse the newly edited Gitbook.
At the beginning, I didn’t pay attention to the error report. Later, I modified and edited the file several times, and found that after each modification, gitbook service would stop and the error in the paper would be reported. Only to find that this is not a mistake of my operation, but the GITbok has a problem, find a problem for a while, no idea, baidu once, the original gitbook itself bug, the original gitbook is a configuration to the wrong configuration. The specific modification methods are as follows:
1. Find gitbook’s configuration file address (Mac system) in the user directory: CD ~ can jump to the current user’s user directory
2. Find ~ /. Gitbook/versions/3.2.3/lib/output/website/copyPluginAssets js file, and then find this file inside all confirm configuration items (2) total, will change the original values true or false.

confirm: false

There are 2 places in total, just change them.