Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docusaurus Build fails when all @docusaurus/plugin-content-docs instances have custom ids #211

Closed
noobinthisgame opened this issue Jun 9, 2022 · 24 comments · Fixed by #228 or #229
Labels
bug Something isn't working

Comments

@noobinthisgame
Copy link

Hi,

when I tried to update to 0.27.0 my build failed because of the following error:

Error: Docusaurus plugin global data not found for "docusaurus-plugin-content-docs" plugin with id "default".

also in the dev server I get the following error:

Screenshot 2022-06-09 at 11 56 46

In my project I'm using custom ids for all instances of @docusaurus/plugin-content-docs.

When I remove the custom plugin id for one instance everything works as expected. In my case it would be great if I could still continue to use custom ids for all my plugin instances.

@weareoutman
Copy link
Member

weareoutman commented Jun 9, 2022

Are you using versioned docs? if not, try to downgrade this theme to 0.26.x. This issue is probably a regression introduced in v0.27.0 when implementing versioned docs. We will try to fix it later.

@weareoutman weareoutman added the bug Something isn't working label Jun 9, 2022
@noobinthisgame
Copy link
Author

noobinthisgame commented Jun 9, 2022

Thanks @weareoutman :) I'm going to stay on 0.26.1 until then.

@weareoutman
Copy link
Member

Thanks for reporting, can you share your config about how you're using custom ids?

@noobinthisgame
Copy link
Author

Essentially I have this in my config which causes the error:

const config = {
  ...
  plugins: [
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'customPlugin1',
        path: './docs/customPlugin1',
        routeBasePath: 'customPlugin1',
        showLastUpdateAuthor: false,
        showLastUpdateTime: false,
        include: ['**/*.md', '**/*.mdx'],
      },
    ],
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'customPlugin2',
        path: './docs/customPlugin2',
        routeBasePath: 'customPlugin2',
        showLastUpdateAuthor: false,
        showLastUpdateTime: false,
        include: ['**/*.md', '**/*.mdx'],
      },
    ],
  ],
}

Seems like this piece of code that got introduced causes the problem:
https://github.com/easyops-cn/docusaurus-search-local/blob/master/docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx#L51-L54

useActiveVersion tries to find a plugin with a default id when no id is passed to it.

Workaround that works with 0.27.0 is to go like this:

const config = {
  ...
  plugins: [
    [
      '@docusaurus/plugin-content-docs',
      {
        path: './docs/customPlugin1',
        routeBasePath: 'customPlugin1',
        showLastUpdateAuthor: false,
        showLastUpdateTime: false,
        include: ['**/*.md', '**/*.mdx'],
      },
    ],
    [
      '@docusaurus/plugin-content-docs',
      {
        id: 'customPlugin2',
        path: './docs/customPlugin2',
        routeBasePath: 'customPlugin2',
        showLastUpdateAuthor: false,
        showLastUpdateTime: false,
        include: ['**/*.md', '**/*.mdx'],
      },
    ],
  ],
}

But is not what I need as in other custom plugins I use the custom ids.

@Cyriuz
Copy link
Contributor

Cyriuz commented Jun 12, 2022

I added a fix for this I think in #205, didn't feel worth it to fix in the old solution that is already not working.

@weareoutman
Copy link
Member

This issue seems not to be fixed yet

@weareoutman
Copy link
Member

This maybe fixed in v0.29.1 via #226 , try it if you're not using versioned docs at the same time (there maybe still issues with versioned docs).

Feel free to reopen it if the problem still exists. But we will track the issue of versioned docs in #224

@weareoutman
Copy link
Member

There is still an issue when the first docs instance has an id other than default. I'll fix it soon.

@weareoutman
Copy link
Member

Finally fixed in v0.29.2. However you should add a new option docsPluginIdForPreferredVersion:

image

@ivishalgandhi
Copy link

ivishalgandhi commented Jul 22, 2022

I am running into the same error message . I am not using plugins any where in the config

Error: Docusaurus plugin global data not found for "docusaurus-plugin-content-docs" plugin with id "default".

As a newbie to Docusaurus and react.js, please share the required configuration for docusaurus.config.js at present I am using

  themes: [
    // ... Your other themes.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,
        // For Docs using Chinese, The `language` is recommended to set to:
        // ```
        // language: ["en", "zh"],
        // ```
      },
    ],
  ],

@weareoutman
Copy link
Member

@ivishalgandhi You should try the suggestion above:

Finally fixed in v0.29.2. However you should add a new option docsPluginIdForPreferredVersion:

image

@ivishalgandhi
Copy link

@weareoutman Thank you. I am not using plugins anywhere in the docusaurus.config.js. how and where should I use above configuration.

@weareoutman
Copy link
Member

@ivishalgandhi Can you share your full docusaurus.config.js? You can remove sensitive data as you wish.

@ivishalgandhi
Copy link

ivishalgandhi commented Jul 22, 2022

@weareoutman this is blog only config ; docs is set to false

/** @type {import('@docusaurus/types').Config} */
const config = {
  title: '',
  tagline: '',
  url: '',
  baseUrl: '/',
  onBrokenLinks: 'throw',
  onBrokenMarkdownLinks: 'warn',
  favicon: 'img/vishal.png',
  organizationName: '', // Usually your GitHub org/user name.
  projectName: ', // Usually your repo name.

  // Even if you don't use internalization, you can use this field to set useful
  // metadata like html lang. For example, if your site is Chinese, you may want
  // to replace "en" with "zh-Hans".
  i18n: {
    defaultLocale: 'en',
    locales: ['en'],
  },
  
  themes: [
    // ... Your other themes.
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        // ... Your options.
        // `hashed` is recommended as long-term-cache of index file is possible.
        hashed: true,
        // For Docs using Chinese, The `language` is recommended to set to:
        // ```
        // language: ["en", "zh"],
        // ```
      },
    ],
  ],

  presets: [
    [
      'classic',
      /** @type {import('@docusaurus/preset-classic').Options} */
      ({
         docs: false,//{
        //   sidebarPath: require.resolve('./sidebars.js'),
        //   // Please change this to your repo.
        //   // Remove this to remove the "edit this page" links.
        //   // editUrl:
        //   //   'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
        // },
        blog: {
          // routeBasePath: '/', // Set this value to '/'.
          blogSidebarTitle: 'All posts',
          path: './blog',
          routeBasePath: '/',
          blogSidebarCount: 'ALL',
          showReadingTime: true,
          // Please change this to your repo.
          // Remove this to remove the "edit this page" links.
          editUrl:

        },
        theme: {
          customCss: require.resolve('./src/css/custom.css'),
        },
      }),
      
    ],
    
  ],

  themeConfig:
    /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
    ({
      navbar: {
        title: 'The Data Column',
        logo: {
          alt: 'logo',
          src: 'img/vishal.png',
        },
        items: [
          // {
          //   type: 'doc',
          //   docId: 'intro',
          //   position: 'left',
          //   label: 'About',
          // },
          { to: 'about', label: 'About', position: 'left' },
          {
            href: 'https://github.com/ivishalgandhi',
            label: 'GitHub',
            position: 'right',
          },
        ],
      },
      footer: {
        style: 'dark',
        copyright: `Copyright © ${new Date().getFullYear()} Vishal Gandhi. Built with Docusaurus.`,
      },
      prism: {
        theme: lightCodeTheme,
        darkTheme: darkCodeTheme,
        additionalLanguages: ['powershell', 'csharp', 'docker', 'bicep'],
      },
    }),

};

module.exports = config;

@weareoutman
Copy link
Member

@ivishalgandhi OK I see, first try setting indexDocs: false for this plugin:

themes: [
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        hashed: true,
        indexDocs: false,
      },
    ],
  ],

@ivishalgandhi
Copy link

@weareoutman

✖ Server
  Compiled with some errors in 8.35s

[ERROR] Docusaurus server-side rendering could not render static page with path /404.html.
[ERROR] Docusaurus server-side rendering could not render static page with path /about.
[ERROR] Docusaurus server-side rendering could not render static page with path /archive.
[ERROR] Docusaurus server-side rendering could not render static page with path /docker-sbom.
[ERROR] Docusaurus server-side rendering could not render static page with path /local-home-lab.
[ERROR] Docusaurus server-side rendering could not render static page with path /markdown-page.
[ERROR] Docusaurus server-side rendering could not render static page with path /search.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/dnsmasq.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/docker.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/docker-desktop.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/lab.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/nginx.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/reverse-proxy.
[ERROR] Docusaurus server-side rendering could not render static page with path /tags/sbom.
[ERROR] Docusaurus server-side rendering could not render static page with path /.


Error: Docusaurus plugin global data not found for "docusaurus-plugin-content-docs" plugin with id "default".

@weareoutman
Copy link
Member

weareoutman commented Jul 22, 2022

@ivishalgandhi ok, I have just reproduced it. It happens when docs disabled. Will fix it later

@ivishalgandhi
Copy link

@weareoutman yes . thank you

@weareoutman
Copy link
Member

@ivishalgandhi Fixed in v0.30.1. P.S. you still need to set indexDocs: false

@ivishalgandhi
Copy link

@weareoutman Thank you. build worked, but search is just spinning, not getting content.

image

 themes: [
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        hashed: true,
        indexDocs: false,
        indexBlog: true,
        blogRouteBasePath: "./blog"
      },
    ],
  ],

@weareoutman
Copy link
Member

@ivishalgandhi I think you should set blogRouteBasePath: "/" according to your blog config

@ivishalgandhi
Copy link

@weareoutman works fine

@aryzing
Copy link

aryzing commented Jan 11, 2023

Is this issue resolved? I just set up a clean install of docusaurus with create-docusaurus@latest and have a single plugin and no preset,

  plugins: [
    [
      "@docusaurus/plugin-content-docs",
      {
        id: "default", // had to set this to default (or remove it, which is equivalent), other values crashed the site
        path: "my-path",
        routeBasePath: "my-base-path",
        sidebarPath: require.resolve("./sidebars.js"),
      },
    ],
  ],

Using an id other than default shows an error in the built doc site,

Docusaurus plugin global data not found for "docusaurus-plugin-content-docs" plugin with id "default".

@weareoutman
Copy link
Member

weareoutman commented Jan 11, 2023

@aryzing Try this option docsPluginIdForPreferredVersion:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants