yarnpkg/yarn · error · Error

Scope should not be empty, got "${str}"

Error message

Scope should not be empty, got "${str}"

What it means

`parsePackageName` treats a leading `@` as a scoped package and splits on `/`. At `create.js:31`, if the first segment is exactly `@` (i.e. the input is `@` or starts with `@/...`), the scope is empty and the name is rejected as 'Scope should not be empty'. This mirrors npm's rule that `@scope/name` requires a non-empty scope.

Source

Thrown at src/cli/commands/create.js:31

export function setFlags(commander: Object) {
  commander.description('Creates new projects from any create-* starter kits.');
}

export function hasWrapper(commander: Object, args: Array<string>): boolean {
  return true;
}

export function parsePackageName(str: string): Object {
  if (str.charAt(0) === '/') {
    throw new Error(`Name should not start with "/", got "${str}"`);
  }
  if (str.charAt(0) === '.') {
    throw new Error(`Name should not start with ".", got "${str}"`);
  }
  const parts = str.split('/');
  const isScoped = str.charAt(0) === '@';
  if (isScoped && parts[0] === '@') {
    throw new Error(`Scope should not be empty, got "${str}"`);
  }
  const scope = isScoped ? parts[0] : '';
  const name = parts[isScoped ? 1 : 0] || '';
  const path = parts.slice(isScoped ? 2 : 1).join('/');
  const fullName = [scope, name].filter(Boolean).join('/');
  const full = [scope, name, path].filter(Boolean).join('/');

  return {fullName, name, scope, path, full};
}

export function coerceCreatePackageName(str: string): Object {
  const pkgNameObj = parsePackageName(str);
  const coercedName = pkgNameObj.name !== '' ? `create-${pkgNameObj.name}` : `create`;
  const coercedPkgNameObj = {
    ...pkgNameObj,
    name: coercedName,
    fullName: [pkgNameObj.scope, coercedName].filter(Boolean).join('/'),
    full: [pkgNameObj.scope, coercedName, pkgNameObj.path].filter(Boolean).join('/'),

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Provide a real scope and name: `yarn create @scope/name` (e.g. `yarn create @nestjs/new`)
  2. For an unscoped kit, drop the `@` entirely: `yarn create react-app`.

Example fix

// before
$ yarn create @/my-kit

// after
$ yarn create @my-org/my-kit
Defensive patterns

Strategy: validation

Validate before calling

function assertScopedNameWellFormed(str: string): void {
  const parts = str.split('/');
  if (str.charAt(0) === '@' && parts[0] === '@') {
    throw new Error(`Scoped name has empty scope: '${str}'. Use '@scope/name'.`);
  }
}

Type guard

function isValidScopedName(s: string): boolean {
  if (s.charAt(0) !== '@') return true;
  const parts = s.split('/');
  return parts.length >= 2 && parts[0].length > 1 && parts[1].length > 0;
}

Prevention

When it happens

Trigger: `isScoped && parts[0] === '@'`, e.g. inputs `@`, `@/foo`, `@/`. Common when a TypeScript path-alias style (`@/...`) or an Angular/Nest convention leaks into the create argument.

Common situations: Copy-pasting a scoped import alias (`@/components`) as the kit name, or forgetting to type the scope after `@`.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/3e538cb0c3bd62c2. Report an issue: GitHub.