Is the default search plugin compatible with GitBook CLI 2.0.0?
0 reputation · 16 Sept 2023, 00:28 UTC
0 reputation · 16 Sept 2023, 00:28 UTC
I want to use the GitBook CLI locked to version 2.0.0 and enable the default search plugin via book.json. However, I am unsure whether the search plugin remains fully functional under this CLI version, given that the CLI only supports GitBook versions >=2.0.0 and the plugin documentation does not specify compatibility details. Are there any known issues between the default search plugin and GitBook CLI 2.0.0? If so, what are they? How can I quickly verify compatibility without performing a full build?
34775 reputation · 16 Sept 2023, 00:49 UTC
The default search plugin is bundled with GitBook CLI 2.0.0 and installed automatically via gitbook install. It relies on Lunr.js and injects a client‑side search widget into the generated HTML, requiring no server‑side changes. Under typical conditions—Node.js 8 or higher and no explicit disable in book.json—the plugin remains fully functional.
GitBook CLI 2.0.0’s minimum supported runtime is Node.js 8. The default search plugin was designed for the CLI 2.x series and continues to be included in the default plugin set. Because the search widget operates entirely in the browser, there are no inherent build‑time incompatibilities with CLI 2.0.0 itself, provided the Node runtime meets the minimum version.
gitbook install and confirm that node_modules/@gitbook/plugin-search appears.gitbook build and open the produced index.html in a browser.ReferenceError: lunr or failed resource loads.gitbook install
Compatibility assumes Node.js >= 8, which is the minimum runtime GitBook CLI 2.0.0 requires. If your Node version is lower, the plugin may fail to install or build. Additionally, if book.json explicitly sets "search": false or overrides the plugin configuration, the default widget will not render. The plugin is no longer actively maintained since the GitBook 3.x transition, but it continues to work with CLI 2.0.0 under the conditions noted above.
Missing diagnostic detail: If you can confirm your current Node.js version, I can refine whether the plugin will install without issues. Otherwise, the steps above will reveal compatibility in your environment.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 16 Sept 2023, 08:12 UTC
You can confirm the default search plugin is active without building the whole book by checking the plugin list and a minimal test build.
gitbook ls; the output should include search among the active plugins.README.md containing a few words, run gitbook install then gitbook build._book/search_index.json; its presence shows the plugin executed.index.html and verify a script tag loading lunr.js and a div id="search-input" (or similar) exists.If any of these checks fail, the plugin is either disabled via book.json or the Node version is below the required 8.