easyops-cn / docusaurus-search-local

Offline/local search for Docusaurus v2/v3
https://easyops-cn.github.io/docusaurus-search-local/
MIT License
700 stars 88 forks source link

Error occurs when building after adding "hi" or "th" to language prop #438

Open andrew-polk opened 2 months ago

andrew-polk commented 2 months ago

After adding "hi" or "th" to the language prop (e.g. language: ["en", "hi"]), docusaurus build gives

TypeError: Cannot read properties of undefined (reading 'init')
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.
    at C:\dev\bloom-docs\node_modules\@docusaurus\core\lib\webpack\utils.js:180:24
    at C:\dev\bloom-docs\node_modules\webpack\lib\MultiCompiler.js:631:14
    at processQueueWorker (C:\dev\bloom-docs\node_modules\webpack\lib\MultiCompiler.js:568:6)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
[INFO] Docusaurus version: 2.4.3
Node version: v18.16.0
error Command failed with exit code 1.

Seems to be caused by https://github.com/MihaiValentin/lunr-languages/issues/101.

andrew-polk commented 2 months ago

Note that while I am using docusaurus v2, this error occurs with v3 as well. I used https://docusaurus.new/, just added the dependency, and added

  themes: [
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        language: ["en", "hi"]
      },
    ],
  ],

to the config.

That gave:

[ERROR] Error: Unable to build website for locale en.
    at tryToBuildLocale (/project/workspace/node_modules/@docusaurus/core/lib/commands/build.js:54:19)
    at async /project/workspace/node_modules/@docusaurus/core/lib/commands/build.js:65:9
    at async mapAsyncSequential (/project/workspace/node_modules/@docusaurus/utils/lib/jsUtils.js:20:24)
    at async Command.build (/project/workspace/node_modules/@docusaurus/core/lib/commands/build.js:63:5) {
  [cause]: TypeError: Cannot read properties of undefined (reading 'init')
      at server.bundle.js:16693:15
      at 1088 (server.bundle.js:14194:70)
      at __webpack_require__ (server.bundle.js:28127:42)
      at 7401 (server.bundle.js:11585:24)
      at __webpack_require__ (server.bundle.js:28127:42)
      at 7489 (server.bundle.js:8814:14)
      at __webpack_require__ (server.bundle.js:28127:42)
      at 6533 (server.bundle.js:9695:21)
      at __webpack_require__ (server.bundle.js:28127:42)
      at server.bundle.js:28193:37
}
weareoutman commented 1 month ago

Seems to be a lunr / lunr-languages issue, please share the result of yarn why lunr and yarn why lunr-languages

andrew-polk commented 1 month ago

In my v2 project:

$ yarn why lunr
...
=> Found "lunr@2.3.9"
info Reasons this module exists
   - "@easyops-cn#docusaurus-search-local" depends on it
   - Hoisted from "@easyops-cn#docusaurus-search-local#lunr"
$ yarn why lunr-languages
...
=> Found "lunr-languages@1.9.0"
info Reasons this module exists
   - "@easyops-cn#docusaurus-search-local" depends on it
   - Hoisted from "@easyops-cn#docusaurus-search-local#lunr-languages"

In the CodeSandbox using v3:

yarn why lunr
...
=> Found "lunr@2.3.9"
info Reasons this module exists
   - "@easyops-cn#docusaurus-search-local" depends on it
   - Hoisted from "@easyops-cn#docusaurus-search-local#lunr"
yarn why lunr-languages
...
=> Found "lunr-languages@1.14.0"
info Reasons this module exists
   - "@easyops-cn#docusaurus-search-local" depends on it
   - Hoisted from "@easyops-cn#docusaurus-search-local#lunr-languages"