docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

npm run build fails with custom plugins

Open sradu opened this issue 3 years ago • 3 comments

If I have a docusaurus.config.js that has:

  plugins: [
    tailwindPlugin,
    webpackPlugin,

  [
      'docusaurus-plugin-openapi-docs',
      ....
  ]
...

npm run build fails with:

[ERROR] TypeError: Cannot read properties of undefined (reading 'endsWith')
    at /Users/user/Work//docs/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:31:21
    at Array.filter (<anonymous>)
    at getDocsPluginConfig (/Users/user/Work//docs/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:28:43)
    at Object.pluginOpenAPIDocs [as plugin] (/Users/user/Work//docs/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:73:19)
    at initializePlugin (/Users/user/Work//docs/node_modules/@docusaurus/core/lib/server/plugins/init.js:83:61)
    at async Promise.all (index 5)

Possible solution

Here https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/main/packages/docusaurus-plugin-openapi-docs/src/index.ts#L33 check if data[0] && data[0].endsWith().

sradu avatar Oct 26 '22 20:10 sradu

Hi @sradu, thanks for reporting the issue. Can you try wrapping the custom plugins in brackets for now?

sserrata avatar Oct 26 '22 20:10 sserrata

[ERROR] Error:  => Bad Docusaurus plugin value plugins[0].
Example valid plugin config:
{
  plugins: [
    ["@docusaurus/plugin-content-docs",options],
    "./myPlugin",
    ["./myPlugin",{someOption: 42}],
    function myPlugin() { },
    [function myPlugin() { },options]
  ],
};

 => Bad Docusaurus plugin value plugins[1].
Example valid plugin config:
{
  plugins: [
    ["@docusaurus/plugin-content-docs",options],
    "./myPlugin",
    ["./myPlugin",{someOption: 42}],
    function myPlugin() { },
    [function myPlugin() { },options]
  ],
};

sradu avatar Oct 26 '22 20:10 sradu

Oops, yeah I see why that wouldn't work. I think we should be able to detect if the plugin is an Array and if the first index is a string before checking to see if it matches the pluginId.

sserrata avatar Oct 26 '22 22:10 sserrata

Hi @sradu, just published a fix in the latest canary release: 0.0.0-496

Appreciate if you can test and report results - thanks!

sserrata avatar Nov 04 '22 13:11 sserrata

Seems to be working 👍

sradu avatar Nov 04 '22 18:11 sradu