『开发技巧』gitbook从入门到放弃(指令错误解决)


0x01:引子

笔者安装此篇文章[GitBook 从懵逼到入门]的方法在M1版MacBookAir配置了gitbook环境。

在执行:gitbook init

报错:TypeError: cb.apply is not a function

Installing GitBook 3.2.3
  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
/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 (fs.js:184:5)
复制代码

注意关键信息: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

 

0x02:历程

参考这篇博客:www.cnblogs.com/cyxroot/p/1…

修改关键信息文件内容:

sudo vim /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js
复制代码

修改一下内容:62-64

fs.stat = statFix(fs.stat)
fs.fstat = statFix(fs.fstat)
fs.lstat = statFix(fs.lstat)
复制代码

注释掉,修改为:

//fs.stat = statFix(fs.stat)
//fs.fstat = statFix(fs.fstat)
//fs.lstat = statFix(fs.lstat)
复制代码

现在运行:gitbook init

报了另一个错误:

warn: no summary file in this book 
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
复制代码

参考这里:stackoverflow.com/questions/6…

I have the same problem just as you. Switch back from latest node version to 12.18.1 LTS.

And everything gonna be ok.

所以笔者尝试对node进行降级:v14.16.1 -> v12.22.1

可以在这里找到V12版本:nodejs.org/dist/latest…

笔者用的MacBookAir,下载的这个:nodejs.org/dist/latest…,进行安装。随后重新安装

现在在运行:gitbook init,就不再报错:

info: create SUMMARY.md 
info: initialization is finished
复制代码

当执行生成电子版书籍遇到错误时,如下:gitbook pdf ./ ./my.pdf

InstallRequiredError: "ebook-convert" is not installed.
Install it from Calibre: https://calibre-ebook.com
复制代码

按照提示,从calibre-ebook.com,下载安装符合系统版本软件安装。笔者下载路径为:download.calibre-ebook.com/5.16.1/cali…

配置ebook-convert路径参考:caibaojian.com/gitbook/bui…

增加PATH路径配置,首先打开这个文件:

sudo vim ~/.zshrc
复制代码

增加路径,添加一条代码:

export PATH="/Applications/calibre.app/Contents/MacOS:$PATH"
复制代码

保存后激活此文件:

source ~/.zshrc
复制代码

 此时测试,ebook-convert指令,命令行执行:ebook-convert

输出:

Usage: ebook-convert input_file output_file [options]

Convert an e-book from one format to another.

input_file is the input and output_file is the output. Both must be specified as the first two arguments to the command.

The output e-book format is guessed from the file extension of output_file. output_file can also be of the special format .EXT where EXT is the output file extension. In this case, the name of the output file is derived from the name of the input file. Note that the filenames must not start with a hyphen. Finally, if output_file has no extension, then it is treated as a folder and an "open e-book" (OEB) consisting of HTML files is written to that folder. These files are the files that would normally have been passed to the output plugin.

After specifying the input and output file you can customize the conversion by specifying various options. The available options depend on the input and output file types. To get help on them specify the input and output file and then use the -h option.

For full documentation of the conversion system see
https://manual.calibre-ebook.com/conversion.html

Whenever you pass arguments to ebook-convert that have spaces in them, enclose the arguments in quotation marks. For example: "/some path/with spaces"

Options:
  --version       show program's version number and exit

  -h, --help      show this help message and exit

  --list-recipes  List builtin recipe names. You can create an e-book from a
                  builtin recipe like this: ebook-convert "Recipe Name.recipe"
                  output.epub


Created by Kovid Goyal <[email protected]>
复制代码

此时,ebook-convert已经安装与测试完成,下面就可以输出pdf书籍,gitbook项目路径下执行:gitbook pdf ./ ./my.pdf

输出:

info: 7 plugins are installed 
info: 6 explicitly listed 
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 9 pages 
info: found 0 asset files 
info: >> generation finished with success in 14.0s ! 
info: >> 1 file(s) generated 
复制代码

0x03:后记

这个博客对你有用的话欢迎收藏转发,也麻烦可爱又爱学的你能赏个赞,菜小宋更博不易,在这里谢过啦。

如果你想学习更多开发技巧与AI算法,欢迎搜索关注笔者公众号“简明AI”,和爱学习讨论的小伙伴一起交流学习。

猜你喜欢

转载自juejin.im/post/7000407157174697992