n8n-io/n8n · error · UserError

You cannot use `--userId` and `--projectId` together. Use on

Error message

You cannot use `--userId` and `--projectId` together. Use one or the other.

What it means

Thrown by `import:credentials` when both `--userId` and `--projectId` are passed. They are mutually exclusive because each credential must be assigned to exactly one owning project — either the user's personal project (via --userId) or an explicit project (--projectId).

Source

Thrown at packages/cli/src/commands/import/credentials.ts:105

	async run(): Promise<void> {
		const { flags } = this;

		if (!flags.input) {
			this.logger.info('An input file or directory with --input must be provided');
			return;
		}

		if (flags.separate) {
			if (fs.existsSync(flags.input)) {
				if (!fs.lstatSync(flags.input).isDirectory()) {
					this.logger.info('The argument to --input must be a directory');
					return;
				}
			}
		}

		if (flags.projectId && flags.userId) {
			throw new UserError(
				'You cannot use `--userId` and `--projectId` together. Use one or the other.',
			);
		}

		if (flags.include && flags.exclude) {
			throw new UserError(
				'You cannot use `--include` and `--exclude` together. Use one or the other.',
			);
		}

		const include = this.parseCredentialProperties(flags.include, '--include');
		const exclude = this.parseCredentialProperties(flags.exclude, '--exclude');

		const credentials = await this.readCredentials({
			inputPath: flags.input,
			separate: flags.separate,
			include,
			exclude,

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Pick one: use `--userId` for the user's personal project, or `--projectId` for a specific project.
  2. Omit both to fall back to the global owner's personal project.

Example fix

// before
n8n import:credentials --input=f.json --userId=A --projectId=B
// after
n8n import:credentials --input=f.json --projectId=B
Defensive patterns

Strategy: validation

Validate before calling

function validateImportFlags(flags: { userId?: string; projectId?: string }) {
  if (flags.userId && flags.projectId) {
    throw new Error('Pass exactly one of --userId or --projectId, not both.');
  }
}
validateImportFlags(flags);

Prevention

When it happens

Trigger: `n8n import:credentials --input=f.json --userId=A --projectId=B`. The check at credentials.ts:104 fires before any DB work.

Common situations: Copy-pasting a command and forgetting to remove one flag; misunderstanding that --userId implies the user's personal project.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/0bda5390ae4f5fe4. Report an issue: GitHub.