YMFE/yapi · error
Plugin Route config Error
Error message
Plugin Route config Error
What it means
addPluginRouter() in server/websocket.js throws 'Plugin Route config Error' when a plugin's websocket route config lacks path, controller, or action. It is a fail-fast config validation for plugin-registered ws routes.
Source
Thrown at server/websocket.js:13
const koaRouter = require('koa-router');
const interfaceController = require('./controllers/interface.js');
const yapi = require('./yapi.js');
const router = koaRouter();
const { createAction } = require("./utils/commons.js")
let pluginsRouterPath = [];
function addPluginRouter(config) {
if (!config.path || !config.controller || !config.action) {
throw new Error('Plugin Route config Error');
}
let method = config.method || 'GET';
let routerPath = '/ws_plugin/' + config.path;
if (pluginsRouterPath.indexOf(routerPath) > -1) {
throw new Error('Plugin Route path conflict, please try rename the path')
}
pluginsRouterPath.push(routerPath);
createAction(router, "/api", config.controller, config.action, routerPath, method, true);
}
function websocket(app) {
createAction(router, "/api", interfaceController, "solveConflict", "/interface/solve_conflict", "get")
yapi.emitHookSync('add_ws_router', addPluginRouter);
app.ws.use(router.routes())View on GitHub (pinned to 59bade3a8a)
Solutions
- Open the plugin's config and ensure every route entry has non-empty path, controller, and action
- Log the config object before addPluginRouter to see which field is missing
- Fix the key spelling to match the expected schema (path/controller/action/method)
- Update or reinstall the plugin to a version compatible with the current yapi
Example fix
// before
addPluginRouter({ path: 'status', controller: myController });
// after
addPluginRouter({ path: 'status', controller: myController, action: 'getStatus', method: 'GET' }); Defensive patterns
Strategy: validation
Validate before calling
function assertWsRouteConfig(config){
['path','controller','action'].forEach(k => {
if (!config || !config[k]) throw new Error(`plugin ws route missing required field: ${k}`);
});
} Type guard
function isValidPluginRouteConfig(c){
return !!c && typeof c.path === 'string' && c.path.length > 0
&& typeof c.controller !== 'undefined' && c.controller !== null
&& typeof c.action === 'string' && c.action.length > 0;
} Try / catch
try {
addPluginRouter(config);
} catch (e) {
if (e.message === 'Plugin Route config Error') {
console.error('Invalid ws plugin route config:', JSON.stringify(config));
} else throw e;
} Prevention
- Validate plugin route configs at plugin load time with a schema check
- Keep plugin route config keys exactly path/controller/action/method
- Pin plugin versions and re-check configs after yapi upgrades
When it happens
Trigger: A plugin calls addPluginRouter({path:'x'}) missing controller or action, or calls addPluginRouter(undefined/null config), usually via a malformed plugin config in the plugin module's exported route list.
Common situations: Typo in plugin config keys (e.g. `handlers` instead of `controller`); plugin version mismatch with yapi plugin API; config object built conditionally so some fields end up undefined.
Related errors
- config.json配置了插件${plugin},但plugins目录没有找到此插件,请安装此插件
- Plugin Route config Error
- Plugin Route path conflict, please try rename the path
- Plugin ${name} Config 配置错误,请检查 yapi-plugin-${name}/index.js
- 插件配置有误,请检查
AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29).
Data as JSON: /api/errors/4028992641f1cb6e.
Report an issue: GitHub.