0

The docusaurus build fails because of error with docusaurus-search-local plugin:

Unable to build website for locale en.
[ERROR] TypeError: Cannot read properties of undefined (reading 'load')
    at html2text (/home/vsts/work/1/s/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js:79:33)
    at /home/vsts/work/1/s/node_modules/@cmfcmf/docusaurus-search-local/lib/server/index.js:287:99
    at async Promise.all (index 0)
    at async Object.postBuild (/home/vsts/work/1/s/node_modules/@cmfcmf/docusaurus-search-local/lib/server/index.js:284:32)
    at async /home/vsts/work/1/s/node_modules/@docusaurus/core/lib/commands/build.js:180:9
    at async Promise.all (index 9)
    at async buildLocale (/home/vsts/work/1/s/node_modules/@docusaurus/core/lib/commands/build.js:176:5)
    at async tryToBuildLocale (/home/vsts/work/1/s/node_modules/@docusaurus/core/lib/commands/build.js:41:20)
    at async mapAsyncSequential (/home/vsts/work/1/s/node_modules/@docusaurus/utils/lib/jsUtils.js:34:24)
    at async Command.build (/home/vsts/work/1/s/node_modules/@docusaurus/core/lib/commands/build.js:76:21)
**your text**

When I exclude the search plugin build works fine.

Using the following versions:

Node: 18.16.0

"@easyops-cn/docusaurus-search-local": "^0.35.0"

Added following to docusaurus.config:

    require.resolve("@easyops-cn/docusaurus-search-local"),
                {
                    hashed: true,
                    language: ["en", "de"],
                    docsRouteBasePath: ['docs'],
                    searchResultLimits: 12
                },

Can you pls. help with inputs.

Tried upgrading node from 16 to 18.

Tried removing docusaurus search and then the build works fine. However, I do not see the search bar which is required.

1 Answer 1

1

The root cause of the error is the Cheerio dependency used in the local-search plugin. As referenced here in the GitHub issue it has been fixed in pull request #218.

Option 1) If you have access to edit the static build the easiest solution is to edit cheerio.default.load(...) to be cheerio.load(...) in the files referenced in the error message. You can also search in the project. This solution is here in GitHub

Option 2) I had to fix the issue in the package-lock.json file however because the CI process creates and deploys our build directory upon merging.

With some trial and error I found that you can first add this to package.json. I added it at the end of the file just before the last closing bracket. You should also update the version of the local-search to 1.1.0.

      "resolutions": {
        "cheerio": "1.0.0-rc.12"
      },

Then delete package-lock.json and rerun npm install to recreate the file.

According to the pull request this will resolve the issue but I found there are two lines defining the version of cheerio and only one is the desired RC12. So after running npm install search for each cheerio reference in package-lock.json and ensure that it reads as follows.

    "cheerio": "1.0.0-rc.12",

Then cross your fingers and run npm run build to validate. I was able to upgrade to Docusaurus 3.5.2 running on Node 20 and React 18.0.1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.