jestjs/jest · error · Error

The --selectProjects option requires the name of at least…

Error message

The --selectProjects option requires the name of at least one project to be specified.
Example usage: jest --selectProjects my-first-project my-second-project

What it means

check() requires that --selectProjects, which takes one or more project display names (args.ts:55-65 in options, validation at 63-68), be given at least one name. With an empty array there is no project to run, so Jest fails fast rather than silently running nothing.

Solutions

  1. Pass at least one project displayName: jest --selectProjects my-first-project my-second-project.
  2. Ensure each named project has displayName set in its config (otherwise selection silently matches nothing later).
  3. If the list is dynamic, skip the flag entirely when the list is empty rather than passing an empty value.

Example fix

// before
jest --selectProjects
// after
jest --selectProjects my-first-project my-second-project
Defensive patterns

Strategy: validation

Validate before calling

function selectProjectsArg(names: string[]): string[] {
  if (names.length === 0) throw new Error('--selectProjects needs >= 1 name');
  return ['--selectProjects', ...names];
}

Type guard

function isNonEmptyStringArray(v: unknown): v is string[] {
  return Array.isArray(v) && v.length > 0 && v.every(x => typeof x === 'string');
}

Prevention

When it happens

Trigger: Running jest --selectProjects with no names; passing --selectProjects= (empty); a script that interpolates a project-name variable that resolved to empty.

Common situations: Automated matrix where the project list is computed and happens to be empty; copy-paste from docs omitting the example args; CI config that conditionally selects projects but the condition yields nothing.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/586aaf13e5a295a1. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-cli/src/args.ts:64

        'Example usage: jest --findRelatedTests ./src/source.js ' +
        './src/index.js.',
    );
  }

  if (
    Object.prototype.hasOwnProperty.call(argv, 'maxWorkers') &&
    argv.maxWorkers === undefined
  ) {
    throw new Error(
      'The --maxWorkers (-w) option requires a number or string to be specified.\n' +
        'Example usage: jest --maxWorkers 2\n' +
        'Example usage: jest --maxWorkers 50%\n' +
        'Or did you mean --watch?',
    );
  }

  if (argv.selectProjects && argv.selectProjects.length === 0) {
    throw new Error(
      'The --selectProjects option requires the name of at least one project to be specified.\n' +
        'Example usage: jest --selectProjects my-first-project my-second-project',
    );
  }

  if (argv.ignoreProjects && argv.ignoreProjects.length === 0) {
    throw new Error(
      'The --ignoreProjects option requires the name of at least one project to be specified.\n' +
        'Example usage: jest --ignoreProjects my-first-project my-second-project',
    );
  }

  if (
    argv.config &&
    !isJSONString(argv.config) &&
    !new RegExp(
      `\\.(${constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)).join('|')})$`,
      'i',

View on GitHub (pinned to 8e6d128e4a)