mac电脑系统安装gitbook,从入门到放弃(指令错误解决)

mac电脑系统安装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

一、历程

修改关键信息文件内容:

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

输出:

```c
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 ```


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

真不爱学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值