YMFE/yapi · error

Plugin ${name} Config 配置错误,请检查 yapi-plugin-${name}/index.js

Error message

Plugin ${name} Config 配置错误,请检查 yapi-plugin-${name}/index.js

What it means

getPluginConfig loads a plugin's config module either from the local exts directory (yapi-plugin-<name>) or from node_modules. If the module resolves to something falsy or not an object, the plugin is considered misconfigured and this error is thrown.

Source

Thrown at common/plugin.js:12

const _ = require('underscore');

function getPluginConfig(name, type) {
  let pluginConfig;
  if (type === 'ext') {
    pluginConfig = require('../exts/yapi-plugin-' + name);
  } else {
    pluginConfig = require('yapi-plugin-' + name);
  }

  if (!pluginConfig || typeof pluginConfig !== 'object') {
    throw new Error(`Plugin ${name} Config 配置错误,请检查 yapi-plugin-${name}/index.js`);
  }

  return {
    server: pluginConfig.server,
    client: pluginConfig.client
  }
}


/**
   * type @string enum[plugin, ext] plugin是外部插件,ext是内部插件
   */
exports.initPlugins = function (plugins, type) {
  if (!plugins) {
    return [];
  }
  if (typeof plugins !== 'object' || !Array.isArray(plugins)) {
    throw new Error('插件配置有误,请检查', plugins);

View on GitHub (pinned to 59bade3a8a)

Solutions

  1. Install the plugin: npm install yapi-plugin-<name> (or create exts/yapi-plugin-<name>/index.js)
  2. Ensure the plugin's index.js exports an object (module.exports = {...} with server/client fields)
  3. Verify the plugin name in config.json matches the installed package name exactly
  4. Rebuild/restart YApi after installing plugins

Example fix

// before (plugin index.js)
module.exports = function () { ... }
// after
module.exports = {
  server: function () { ... },
  client: function () { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

const mods = ['yapi-plugin-' + name];
let cfg = null;
try { cfg = require('../exts/yapi-plugin-' + name); } catch (e) {}
if (!cfg) { try { cfg = require('yapi-plugin-' + name); } catch (e) {} }
if (!cfg || typeof cfg !== 'object') throw new Error('plugin ' + name + ' missing or invalid');

Type guard

function isValidPluginConfig(c){ return !!c && typeof c === 'object' && ('server' in c || 'client' in c); }

Try / catch

try {
  const cfg = getPluginConfig(name, type);
} catch (e) {
  console.error('Plugin not installed or exports invalid:', name);
  process.exit(1);
}

Prevention

When it happens

Trigger: initPlugins resolves a plugin name listed in config.json but require('../exts/yapi-plugin-<name>') or require('yapi-plugin-<name>') returns nothing valid — e.g. plugin not installed, module.exports missing, or exports not an object.

Common situations: Plugin listed in config.json but never installed via npm; plugin's index.js exports nothing or exports a function instead of an object; typo in plugin name; plugin removed from node_modules after deployment.

Related errors


AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29). Data as JSON: /api/errors/328734f2dcc9d6f0. Report an issue: GitHub.