Hmbown/CodeWhale · error · Error

npm pack metadata did not include a filename

Error message

npm pack metadata did not include a filename: ${trimmed}

What it means

parsePackJson parses the JSON output of `npm pack --json` and returns the tarball filename. The library throws this error when the parsed metadata exists but carries no `filename` field, meaning npm produced metadata the smoke test cannot locate a tarball from.

Solutions

  1. Run `npm pack --json` manually in the wrapper package directory and inspect whether the output contains a `filename` field.
  2. Upgrade or pin npm to a version whose `pack --json` output includes `filename` (npm 7+).
  3. Check that the pack command runs in the intended package directory and not a workspace root that packs nothing.

Example fix

// before
const first = Array.isArray(parsed) ? parsed[0] : parsed;
if (!first || !first.filename) {
  throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);
}
// after
const first = Array.isArray(parsed) ? parsed[0] : parsed;
if (!first || (!first.filename && !first.name)) {
  throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);
}
const filename = first.filename ?? `${first.name}-${first.version}.tgz`;
Defensive patterns

Strategy: type-guard

Validate before calling

const parsed = JSON.parse(npmPackOutput);
const first = Array.isArray(parsed) ? parsed[0] : parsed;
if (typeof first?.filename !== "string" || !first.filename) throw new Error("pack metadata missing filename");

Type guard

function hasPackFilename(v: unknown): v is { filename: string } {
  return typeof v === "object" && v !== null && typeof (v as any).filename === "string" && (v as any).filename.length > 0;
}

Try / catch

try {
  const filename = await tarball();
} catch (err) {
  if (String(err.message).includes("npm pack")) {
    console.error("Unexpected npm pack output shape; check npm version:", err.message);
  }
  throw err;
}

Prevention

When it happens

Trigger: `npm pack --json` succeeded and returned parseable JSON, but the first element (or object) lacks a `filename` property — e.g. an npm version emitting a different metadata shape, or an empty/placeholder object.

Common situations: Older or newer npm versions changed the pack --json schema; running inside a workspace where pack output is an empty array; a corrupted or intercepted npm pack output.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/1ee0e27ae2578378. Report an issue: GitHub.

Appendix: source

Thrown at scripts/release/npm-wrapper-smoke.js:132

    server.listen(0, "127.0.0.1", () => {
      const address = server.address();
      resolve({
        baseUrl: `http://127.0.0.1:${address.port}/`,
        server,
      });
    });
  });
}

function parsePackJson(stdout) {
  const trimmed = stdout.trim();
  if (!trimmed) {
    throw new Error("npm pack did not return package metadata");
  }
  const parsed = JSON.parse(trimmed);
  const first = Array.isArray(parsed) ? parsed[0] : parsed;
  if (!first || !first.filename) {
    throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);
  }
  return first.filename;
}

async function removeSmokeWorkspace(tempRoot, remove = fsp.rm) {
  await remove(tempRoot, {
    force: true,
    recursive: true,
    // Windows can report ENOTEMPTY briefly while completed binary downloads
    // are still being released by the filesystem. fs.rm retries ENOTEMPTY
    // (and the other documented transient removal errors) with linear
    // backoff; the finite cap still surfaces a persistent cleanup failure.
    maxRetries: CLEANUP_MAX_RETRIES,
    retryDelay: CLEANUP_RETRY_DELAY_MS,
  });
}

async function main() {

View on GitHub (pinned to 433685b202)