『开发技巧』gitbook从入门到放弃(指令错误解决)
Posted 小宋是呢
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了『开发技巧』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:历程
参考这篇博客:https://www.cnblogs.com/cyxroot/p/13754475.html
修改关键信息文件内容:
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
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版本:https://nodejs.org/dist/latest-v12.x/
笔者用的MacBookAir,下载的这个:https://nodejs.org/dist/latest-v12.x/node-v12.22.1.pkg,进行安装。随后重新安装
现在在运行: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
按照提示,从https://calibre-ebook.com,下载安装符合系统版本软件安装。笔者下载路径为:https://download.calibre-ebook.com/5.16.1/calibre-5.16.1.dmg
配置ebook-convert路径参考:http://caibaojian.com/gitbook/build/ebookconvert.html
增加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 <kovid@kovidgoyal.net>
此时,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”,和爱学习讨论的小伙伴一起交流学习。
以上是关于『开发技巧』gitbook从入门到放弃(指令错误解决)的主要内容,如果未能解决你的问题,请参考以下文章
CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维