yarnpkg/yarn · error · Error

Name should not start with "/", got "${str}"

Error message

Name should not start with "/", got "${str}"

What it means

`yarn create <kit>` calls `parsePackageName` to split the argument into scope/name/path. At `create.js:23` it rejects a leading `/` because a package name starting with a slash is not a valid npm identifier and would resolve ambiguously. This is a pre-resolution input validation, before any network/linker work.

Source

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

import type {Reporter} from '../../reporters/index.js';
import * as child from '../../util/child.js';
import {makeEnv} from '../../util/execute-lifecycle-script';
import * as fs from '../../util/fs.js';
import {run as runGlobal, getBinFolder} from './global.js';

const path = require('path');

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};
}

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Remove the leading slash: `yarn create react-app`.
  2. If you meant a local directory starter, use an explicit path form supported by the create-* kit rather than a bare leading slash.

Example fix

// before
$ yarn create /react-app my-app

// after
$ yarn create react-app my-app
Defensive patterns

Strategy: validation

Validate before calling

function assertValidCreateName(str: string): void {
  if (str.charAt(0) === '/') {
    throw new Error(`Package name must not start with '/': got '${str}'`);
  }
}
// assertValidCreateName(builderName);

Type guard

function hasNoLeadingSlash(s: string): boolean {
  return s.length > 0 && s.charAt(0) !== '/';
}

Prevention

When it happens

Trigger: `str.charAt(0) === '/'` — the first character of the builder argument is a forward slash, e.g. `yarn create /react-app`.

Common situations: Autocompleted or pasted path-like argument (`/react-app`), shell glob/tilde expansion leaking a slash, or confusion between a file path and a package name.

Related errors


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