yarnpkg/yarn · error · MessageError

noVersion

Error message

noVersion

What it means

Right after the `name` check, `yarn pack` requires a `version` (pack.js:188) because the tarball filename embeds the version (`${name}-v${version}.tgz`, pack.js:190). A package.json with `name` but no `version` throws noVersion.

Source

Thrown at src/cli/commands/pack.js:188

  commander.option('-f, --filename <filename>', 'filename');
}

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

export async function run(
  config: Config,
  reporter: Reporter,
  flags: {filename?: string},
  args?: Array<string>,
): Promise<void> {
  const pkg = await config.readRootManifest();
  if (!pkg.name) {
    throw new MessageError(reporter.lang('noName'));
  }
  if (!pkg.version) {
    throw new MessageError(reporter.lang('noVersion'));
  }

  const normaliseScope = name => (name[0] === '@' ? name.substr(1).replace('/', '-') : name);
  const filename = flags.filename || path.join(config.cwd, `${normaliseScope(pkg.name)}-v${pkg.version}.tgz`);

  await config.executeLifecycleScript('prepack');

  const stream = await pack(config);

  await new Promise((resolve, reject) => {
    stream.pipe(fs2.createWriteStream(filename));
    stream.on('error', reject);
    stream.on('close', resolve);
  });

  await config.executeLifecycleScript('postpack');

  reporter.success(reporter.lang('packWroteTarball', filename));

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Add a semver `version` to package.json (e.g., "1.0.0").
  2. Run `yarn version --new-version <x.y.z>` to set it before packing.
  3. Ensure any version-bumping step (e.g., standard-version, release tool) runs before `yarn pack`.

Example fix

// before — package.json
{
  "name": "mylib"
}
// after
{
  "name": "mylib",
  "version": "1.0.0"
}
Defensive patterns

Strategy: validation

Validate before calling

const pkg = require('./package.json');
if (!pkg.version) {
  throw new Error('Cannot pack: package.json has no "version".');
}

Type guard

function hasVersion(pkg) {
  return typeof pkg === 'object' && pkg !== null && typeof pkg.version === 'string' && pkg.version.length > 0;
}

Try / catch

try {
  await runYarn(['pack']);
} catch (e) {
  if (/noVersion/.test(e.message)) {
    console.error('Set a "version" in package.json before packing.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `yarn pack` when package.json has a `name` but no `version` field (or version is empty).

Common situations: Project initialized with `yarn init` and version skipped/blanked; version managed by another tool that hasn't written it yet at pack time.

Related errors


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