RocketChat/Rocket.Chat · critical · Meteor.Error

Username ${adminUser.username} already exists

Error message

Username ${adminUser.username} already exists

What it means

Companion guard to the email check: in TEST_MODE startup, checkUsernameAvailability(adminUser.username) must return true for the fixture username 'rocketchat.internal.admin.test'. If the username is taken (reserved by another document, or held by a user with a different _id), startup throws and the seed is aborted.

Source

Thrown at apps/meteor/server/startup/initialData.ts:238

			],
			status: UserStatus.OFFLINE,
			statusDefault: UserStatus.ONLINE,
			utcOffset: 0,
			active: true,
			type: 'user',
		};

		console.log(colors.green(`Name: ${adminUser.name}`));
		console.log(colors.green(`Email: ${adminUser.emails![0].address}`));
		console.log(colors.green(`Username: ${adminUser.username}`));
		console.log(colors.green(`Password: ${adminUser._id}`));

		if (await Users.findOneByEmailAddress(adminUser.emails![0].address)) {
			throw new Meteor.Error(`Email ${adminUser.emails![0].address} already exists`, "Rocket.Chat can't run in test mode");
		}

		if (!(await checkUsernameAvailability(adminUser.username!))) {
			throw new Meteor.Error(`Username ${adminUser.username} already exists`, "Rocket.Chat can't run in test mode");
		}

		await Users.create(adminUser);

		await Accounts.setPasswordAsync(adminUser._id, adminUser._id);

		await addUserRolesAsync(adminUser._id, ['admin']);

		if (settings.get('Show_Setup_Wizard') === 'pending') {
			(await Settings.updateValueById('Show_Setup_Wizard', 'in_progress')).modifiedCount &&
				void notifyOnSettingChangedById('Show_Setup_Wizard');
		}

		await addUserToDefaultChannels(adminUser as IUser, true);

		// Create sample call history for API tests
		return addCallHistoryTestData('rocketchat.internal.admin.test', 'rocket.cat');
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Clean leftover documents with that username: db.users.remove({username:'rocketchat.internal.admin.test'}) then restart.
  2. Use a fresh/reset database for every TEST_MODE run (this is the expected workflow).
  3. If it persists, check reserved-usernames settings and the username unique index for orphans.

Example fix

# before: username collision blocks startup
mongosh rock_chat --eval 'db.users.find({username:"rocketchat.internal.admin.test"}).pretty()'

# after: purge and restart
mongosh rock_chat --eval 'db.users.remove({username:"rocketchat.internal.admin.test"})'
Defensive patterns

Strategy: validation

Validate before calling

// Pre-start check: fixture username must be available
const available = await checkUsernameAvailability('rocketchat.internal.admin.test');
if (!available && TEST_MODE) { /* purge leftovers: db.users.remove({username:'rocketchat.internal.admin.test'}) */ }

Prevention

When it happens

Trigger: TEST_MODE startup against a database where the username 'rocketchat.internal.admin.test' already exists — e.g. a previous test-mode run created it, then the _id row was removed but the username remained, or another user registered that name.

Common situations: Partially cleaned test databases (username index still holds the name); repeated CI runs on the same Mongo instance; username collisions after imports.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/598436d0b1a0b05f. Report an issue: GitHub.