使用Gitbook写一手漂亮的在线文档

前端技术
2025-07-12 08:57:38
分享



检查依赖环境

node -v

1752307836634.png


安装Gitbook


执行以下命令安装gitbook

npm install gitbook-cli -g


执行后输出内容如下:

D:\WORK\bullet-docs>npm install gitbook-cli -g
npm warn deprecated q@1.5.0: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.
npm warn deprecated
npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp)

added 21 packages in 13s
npm notice
npm notice New major version of npm available! 10.8.2 -> 11.4.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.4.2
npm notice To update run: npm install -g npm@11.4.2
npm notice

提示审计npm,到时执行后提示不支持,可能是node版本问题,故通过nvm切换版本到20.19.0


C:\Windows\System32>nvm list

    20.19.0
  * 18.20.7 (Currently using 64-bit executable)
    18.12.1

C:\Windows\System32>nvm use 20.19.0
Now using node v20.19.0 (64-bit)

C:\Windows\System32>node -v
v20.19.0


升级到node20.19后,gitbook正常安装

D:\WORK\bullet-docs>npm install gitbook-cli -g
npm warn deprecated q@1.5.0: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.
npm warn deprecated
npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp)

added 21 packages in 10s
PS D:\WORK\bullet-docs> gitbook serve
Error loading version latest: Error: Cannot find module 'spdx-license-ids'
Require stack:
- C:\Users\marker\.gitbook\versions\3.2.3\node_modules\read-installed\node_modules\read-package-json\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-expression-parse\scan.js

提示找不到 spdx-license-ids 。进入到这个C:\Users\marker\.gitbook目录删除version。再次执行gitbook serve重装gitbook


查询gitbook支持的node版本,啊,这么低


GitBook 官方支持的 Node.js 版本取决于你使用的 GitBook 版本:

GitBook (Legacy)

  • 最后官方维护的版本是 GitBook 3.x(传统版本),支持:

    • Node.js 8.x - 12.x(推荐 Node 10.x)

    • 更高版本(如 Node 14+)可能会遇到兼容性问题。

GitBook (Newer CLI / GitBook.com 版本)

  • 较新的 GitBook CLI(如 gitbook-cli)可能支持:

    • Node.js 12.x - 14.x

    • 部分用户报告 Node 16+ 也能运行,但可能有依赖问题。


1752308607177.png




 


 


The End
免责声明:本文系转载,版权归原作者所有;旨在传递信息,不代表本站观点和立场。