{"record":{"id":"328734f2dcc9d6f0","repo":"YMFE/yapi","slug":"plugin-name-config-yapi-plugin-name","errorCode":null,"errorMessage":"Plugin ${name} Config 配置错误，请检查 yapi-plugin-${name}/index.js","messagePattern":"Plugin (.+?) Config 配置错误，请检查 yapi-plugin-(.+?)/index\\.js","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/plugin.js","lineNumber":12,"sourceCode":"const _ = require('underscore');\n\nfunction getPluginConfig(name, type) {\n  let pluginConfig;\n  if (type === 'ext') {\n    pluginConfig = require('../exts/yapi-plugin-' + name);\n  } else {\n    pluginConfig = require('yapi-plugin-' + name);\n  }\n\n  if (!pluginConfig || typeof pluginConfig !== 'object') {\n    throw new Error(`Plugin ${name} Config 配置错误，请检查 yapi-plugin-${name}/index.js`);\n  }\n\n  return {\n    server: pluginConfig.server,\n    client: pluginConfig.client\n  }\n}\n\n\n/**\n   * type @string enum[plugin, ext] plugin是外部插件，ext是内部插件\n   */\nexports.initPlugins = function (plugins, type) {\n  if (!plugins) {\n    return [];\n  }\n  if (typeof plugins !== 'object' || !Array.isArray(plugins)) {\n    throw new Error('插件配置有误，请检查', plugins);","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/common/plugin.js#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the plugin: npm install yapi-plugin-<name> (or create exts/yapi-plugin-<name>/index.js)","Ensure the plugin's index.js exports an object (module.exports = {...} with server/client fields)","Verify the plugin name in config.json matches the installed package name exactly","Rebuild/restart YApi after installing plugins"],"exampleFix":"// before (plugin index.js)\nmodule.exports = function () { ... }\n// after\nmodule.exports = {\n  server: function () { ... },\n  client: function () { ... }\n}","handlingStrategy":"validation","validationCode":"const mods = ['yapi-plugin-' + name];\nlet cfg = null;\ntry { cfg = require('../exts/yapi-plugin-' + name); } catch (e) {}\nif (!cfg) { try { cfg = require('yapi-plugin-' + name); } catch (e) {} }\nif (!cfg || typeof cfg !== 'object') throw new Error('plugin ' + name + ' missing or invalid');","typeGuard":"function isValidPluginConfig(c){ return !!c && typeof c === 'object' && ('server' in c || 'client' in c); }","tryCatchPattern":"try {\n  const cfg = getPluginConfig(name, type);\n} catch (e) {\n  console.error('Plugin not installed or exports invalid:', name);\n  process.exit(1);\n}","preventionTips":["Keep config.json plugins list in sync with installed npm packages","Ensure every plugin index.js exports an object with server/client keys","Run a startup validation that requires all listed plugins before boot","Pin plugin versions in package.json"],"tags":["plugins","configuration","require"],"backgroundTag":"invalid-plugin-config","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}