{"record":{"id":"34fc9c3ca82cf692","repo":"YMFE/yapi","slug":"error","errorCode":null,"errorMessage":"插件配置有误，请检查","messagePattern":"插件配置有误，请检查","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/plugin.js","lineNumber":30,"sourceCode":"    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);\n  }\n\n  plugins = plugins.map(item => {\n    let pluginConfig;\n    if (item && typeof item === 'string') {\n      pluginConfig = getPluginConfig(item, type);\n      return Object.assign({}, pluginConfig, { name: item, enable: true })\n    } else if (item && typeof item === 'object') {\n      pluginConfig = getPluginConfig(item.name, type);\n      return Object.assign({},\n        pluginConfig,\n        {\n          name: item.name,\n          options: item.options,\n          enable: item.enable === false ? false : true\n        })\n    }\n  })","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/common/plugin.js#L12-L48","documentation":"initPlugins expects the plugins list (from config.json) to be an array. If it is not an array (or is a non-object), the configuration is malformed and this error is thrown before any plugin is loaded.","triggerScenarios":"config.json's plugins field is a string, object, boolean, or missing-in-a-wrong-way instead of an array of plugin names/objects when initPlugins is invoked.","commonSituations":"Hand-edited config.json turning plugins into a string; config loader merging that replaced the array; environment-specific config overriding plugins with wrong type.","solutions":["Edit config.json so plugins is an array, e.g. \"plugins\": [\"name1\", \"name2\"]","Validate the config JSON parses correctly and plugins was not flattened by a merge tool","Restart the server after fixing config"],"exampleFix":"// before (config.json)\n\"plugins\": \"oauth\"\n// after\n\"plugins\": [\"oauth\"]","handlingStrategy":"validation","validationCode":"function assertPluginsArray(config){\n  if (!Array.isArray(config.plugins)) throw new Error('config.plugins must be an array');\n  config.plugins.forEach(p => { if (p && typeof p !== 'string' && typeof p !== 'object') throw new Error('bad plugin entry'); });\n}","typeGuard":"function isPluginList(v){ return v == null || (Array.isArray(v) && v.every(x => typeof x === 'string' || (x && typeof x === 'object'))); }","tryCatchPattern":"try {\n  exports.initPlugins(config.plugins, 'server');\n} catch (e) {\n  console.error('Check config.json plugins field:', e.message);\n  process.exit(1);\n}","preventionTips":["Always define plugins as an array in config.json (empty array if none)","Validate config.json with a schema before server start","Avoid ad-hoc config merge tools that can change types","Review config diffs after upgrades"],"tags":["plugins","configuration","validation"],"backgroundTag":"invalid-plugin-config","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}