YMFE/yapi · critical
初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}
Error message
初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message} What it means
During installation, setupSql tries to create the initial admin account (account name from yapi.WEBCONFIG.adminAccount) and throws this error in the rejection handler when the user-creation promise fails. The inner err.message reveals the actual DB/validation failure.
Source
Thrown at server/install.js:146
let followCol = mongoose.connection.db.collection('follow');
followCol.createIndex({
uid: 1
});
followCol.createIndex({
project_id: 1
});
result.then(
function() {
fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'));
console.log(
`初始化管理员账号成功,账号名:"${yapi.WEBCONFIG.adminAccount}",密码:"ymfe.org"`
); // eslint-disable-line
process.exit(0);
},
function(err) {
throw new Error(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line
}
);
})
.catch(function(err) {
throw new Error(err.message);
});
}
install();
View on GitHub (pinned to 59bade3a8a)
Solutions
- Check err.message appended to the error for the root cause (connection refused, duplicate key, validation).
- Ensure MongoDB is running and db connection settings in config.json are correct.
- Set a valid adminAccount in config.json (non-empty email format).
- If the admin already exists, skip re-install or remove the existing user/collection first.
Example fix
// before (config.json) "adminAccount": "" // after "adminAccount": "admin@yapi.local"
Defensive patterns
Strategy: validation
Validate before calling
if (!config.adminAccount) throw new Error('adminAccount required in config.json');
// and verify DB reachable before install:
await dbModule.connect(); Try / catch
try {
await setupSql();
} catch (e) {
if (e.message.includes('初始化管理员账号')) {
console.error('Admin seeding failed:', e.message); // inspect inner err.message
} else { throw e; }
} Prevention
- Ensure MongoDB is up and reachable before running the installer.
- Set a valid, non-empty adminAccount (email format) in config.json.
- Run install only once per environment.
When it happens
Trigger: install() -> setupSql(): the mongoose save/create of the admin user rejects — e.g. DB connection issue, duplicate admin account, schema validation failure on the user model.
Common situations: MongoDB not running or unreachable at install time, invalid adminAccount in config.json (empty/not an email-like value), admin account already exists from a prior partial install.
Related errors
AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29).
Data as JSON: /api/errors/a24ec03e408e1f39.
Report an issue: GitHub.