『开发技巧』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

参考这里:https://stackoverflow.com/questions/61538769/gitbook-init-error-typeerror-err-invalid-arg-type-the-data-argument-must-b

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”,和爱学习讨论的小伙伴一起交流学习。

 

小宋是呢 CSDN认证博客专家 AI工程师 深度学习领域专家
作者简介:深度学习开发分享博主。全网粉丝3W+,阅读量200W+。
CSDN深度学习博客专家以及微信公众号《简明AI》主要作者。创作内容是基于深度学习的理论学习与应用开发技术分享,致力于最简单明了AI技术分享与最实用AI应用教程。

撰写并发表深度学习论文两篇,获得国家级及省级一等奖奖项八次,以第一作者授权实用新型及发明专利共计十余项,天池与BDCI比赛Top10奖项数次。

在某公司担任算法工程师,从事计算机视觉及时序序列数据的检测识别;深度学习工程化经验丰富,擅长针对新算法研究与应用,包括对模型调优、模型转化及多平台部署等。
相关推荐
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页
实付 69.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值