YMFE/yapi · error
插件配置有误,请检查
Error message
插件配置有误,请检查
What it means
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.
Source
Thrown at common/plugin.js:30
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);
}
plugins = plugins.map(item => {
let pluginConfig;
if (item && typeof item === 'string') {
pluginConfig = getPluginConfig(item, type);
return Object.assign({}, pluginConfig, { name: item, enable: true })
} else if (item && typeof item === 'object') {
pluginConfig = getPluginConfig(item.name, type);
return Object.assign({},
pluginConfig,
{
name: item.name,
options: item.options,
enable: item.enable === false ? false : true
})
}
})View on GitHub (pinned to 59bade3a8a)
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
Example fix
// before (config.json) "plugins": "oauth" // after "plugins": ["oauth"]
Defensive patterns
Strategy: validation
Validate before calling
function assertPluginsArray(config){
if (!Array.isArray(config.plugins)) throw new Error('config.plugins must be an array');
config.plugins.forEach(p => { if (p && typeof p !== 'string' && typeof p !== 'object') throw new Error('bad plugin entry'); });
} Type guard
function isPluginList(v){ return v == null || (Array.isArray(v) && v.every(x => typeof x === 'string' || (x && typeof x === 'object'))); } Try / catch
try {
exports.initPlugins(config.plugins, 'server');
} catch (e) {
console.error('Check config.json plugins field:', e.message);
process.exit(1);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Hand-edited config.json turning plugins into a string; config loader merging that replaced the array; environment-specific config overriding plugins with wrong type.
Related errors
- Plugin ${name} Config 配置错误,请检查 yapi-plugin-${name}/index.js
- This method name(${method}) is not exist.
- 返回数据格式不是 JSON
- config.json配置了插件${plugin},但plugins目录没有找到此插件,请安装此插件
- Plugin Route config Error
AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29).
Data as JSON: /api/errors/34fc9c3ca82cf692.
Report an issue: GitHub.