cmfcmf / docusaurus-search-local

Offline / Local Search for Docusaurus v2. Try it live at:
https://cmfcmf.github.io/OpenWeatherMap-PHP-API/
MIT License
438 stars 67 forks source link

Unable to run yarn build after adding plugin #99

Closed dkobran closed 2 years ago

dkobran commented 2 years ago

Please describe the bug you are seeing

I am unable to successfully run yarn build after installing this plugin.

How can we best reproduce the bug?

I just followed the two steps from the instructions:

yarn add @cmfcmf/docusaurus-search-local

and adding the plugin to docusaurus.config.js with:

require.resolve("@cmfcmf/docusaurus-search-local"),

When I run yarn build, I get this error:

[ERROR] Unable to build website for locale en.
[ERROR] Error: docusaurus_tag meta tag not found. This is a bug and should never happen.
    at getDocusaurusTag (/Users/danielkobran/Documents/ps_docs/node_modules/@cmfcmf/docusaurus-search-local/lib/server/parse.js:186:15)
    at /Users/danielkobran/Documents/ps_docs/node_modules/@cmfcmf/docusaurus-search-local/lib/server/index.js:287:58
    at async Promise.all (index 0)
    at async Object.postBuild (/Users/danielkobran/Documents/ps_docs/node_modules/@cmfcmf/docusaurus-search-local/lib/server/index.js:283:32)
    at async /Users/danielkobran/Documents/ps_docs/node_modules/@docusaurus/core/lib/commands/build.js:153:9
    at async Promise.all (index 6)
    at async buildLocale (/Users/danielkobran/Documents/ps_docs/node_modules/@docusaurus/core/lib/commands/build.js:149:5)
    at async tryToBuildLocale (/Users/danielkobran/Documents/ps_docs/node_modules/@docusaurus/core/lib/commands/build.js:33:20)
    at async mapAsyncSequencial (/Users/danielkobran/Documents/ps_docs/node_modules/@docusaurus/utils/lib/index.js:262:24)
    at async build (/Users/danielkobran/Documents/ps_docs/node_modules/@docusaurus/core/lib/commands/build.js:68:25)
error Command failed with exit code 1.

Which version of Docusaurus and @cmfcmf/docusaurus-search-local are you using?

yarn list v1.22.17 ├─ @cmfcmf/docusaurus-search-local@0.10.0 ├─ @docusaurus/core@2.0.0-beta.14 ├─ @docusaurus/cssnano-preset@2.0.0-beta.14 ├─ @docusaurus/logger@2.0.0-beta.14 ├─ @docusaurus/mdx-loader@2.0.0-beta.14 ├─ @docusaurus/plugin-content-blog@2.0.0-beta.14 ├─ @docusaurus/plugin-content-docs@2.0.0-beta.14 ├─ @docusaurus/plugin-content-pages@2.0.0-beta.14 ├─ @docusaurus/plugin-debug@2.0.0-beta.14 ├─ @docusaurus/plugin-google-analytics@2.0.0-beta.14 ├─ @docusaurus/plugin-google-gtag@2.0.0-beta.14 ├─ @docusaurus/plugin-sitemap@2.0.0-beta.14 ├─ @docusaurus/preset-classic@2.0.0-beta.14 ├─ @docusaurus/react-loadable@5.5.2 ├─ @docusaurus/theme-classic@2.0.0-beta.14 ├─ @docusaurus/theme-common@2.0.0-beta.14 ├─ @docusaurus/theme-search-algolia@2.0.0-beta.14 ├─ @docusaurus/theme-translations@2.0.0-beta.14 ├─ @docusaurus/utils-common@2.0.0-beta.14 ├─ @docusaurus/utils-validation@2.0.0-beta.14 └─ @docusaurus/utils@2.0.0-beta.14

Which Node.js version are you using?

v16.13.2

Which theme are you using?

Yes, I am using @docusaurus/theme-classic

How does your plugin config look like?

plugins: [
    [
      require.resolve("@cmfcmf/docusaurus-search-local"),
      {
        indexDocs: true,
      },
    ],
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'core',
        path: 'core',
        routeBasePath: 'core',
        sidebarPath: undefined,
      },
    ],
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'portal',
        path: 'portal',
        routeBasePath: 'portal',
        sidebarPath: undefined,
      }
    ],
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'account-management',
        path: 'account-management',
        routeBasePath: 'account-management',
        sidebarPath: 'sidebarsAccount.js',
        // sidebarCollapsed: false,
      }
    ],
  ]

Additional context

No response

dkobran commented 2 years ago

I tried 2.0.0-beta.15 just to see if it was a version issue and I got the same result

homotechsual commented 2 years ago

I'm seeing this too.

homotechsual commented 2 years ago

I fixed this - I have a page locally which had no <main> content element which was missing the required meta tags.

JulesBlm commented 2 years ago

I ran in to this bug too and found out it was because I had a page without a <Layout> . Adding import Layout from '@theme/Layout'; and wrapping the page in <Layout> fixed it.

nida commented 2 years ago

@homotechsual @JulesBlm I am running into the same issue, could explain what is

content element and page without Layout means?

homotechsual commented 2 years ago

This has resurfaced on Beta16 without changes to the rest of the code.

homotechsual commented 2 years ago

For Beta16 this is a breaking change caused by https://github.com/facebook/docusaurus/pull/6707

homotechsual commented 2 years ago

The solution would either be adjusting to look for the now default docsearch:docusaurus_tag meta element or overriding the SearchMetadata component to include the former defaults:

{language && <meta name="language" content={language} />}
{version && <meta name="version" content={version} />}
{tag && <meta name="docusaurus_tag" content={tag} />}
homotechsual commented 2 years ago

I've tested this by swizzling that component and re-adding those and it allows builds on B16.

cmfcmf commented 2 years ago

Thanks for figuring this out @homotechsual! @slorber what is the recommended way to go forward here? This plugin used the docusaurus_version to figure out the version of pages when indexing. Should we overwrite the SearchMetadata component to re-add it, or should we simply use docsearch:version now?

slorber commented 2 years ago

sorry missed the notification

I'm going to restore/duplicate those tags so that nobody is affected any more

Pages will be a bit heavier but not much 🤷‍♂️ not sure how to deal with this to make it convenient for most users and at the same time it doesn't look great if you read algolia meta in third-party plugins

https://github.com/facebook/docusaurus/pull/6827

cmfcmf commented 2 years ago

Thank you @slorber!

As for the original issue, please make sure to wrap your custom pages in <Layout> from @theme/layout, like you can see here: https://github.com/cmfcmf/docusaurus-search-local/blob/84c72c3d98c6e0d578c7799274f4a33a896c1425/packages/example-docs/src/pages/index.js#L31-L38

Please let me know if you continue to encounter this issue with the latest Docusaurus beta (v2.0.0-beta.17), then I'm happy to reopen this.