{"record":{"id":"1ee0e27ae2578378","repo":"Hmbown/CodeWhale","slug":"npm-pack-metadata-did-not-include-a-filename-trimmed","errorCode":null,"errorMessage":"npm pack metadata did not include a filename: ${trimmed}","messagePattern":"npm pack metadata did not include a filename: (.+?)","errorType":"console","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/release/npm-wrapper-smoke.js","lineNumber":132,"sourceCode":"    server.listen(0, \"127.0.0.1\", () => {\n      const address = server.address();\n      resolve({\n        baseUrl: `http://127.0.0.1:${address.port}/`,\n        server,\n      });\n    });\n  });\n}\n\nfunction parsePackJson(stdout) {\n  const trimmed = stdout.trim();\n  if (!trimmed) {\n    throw new Error(\"npm pack did not return package metadata\");\n  }\n  const parsed = JSON.parse(trimmed);\n  const first = Array.isArray(parsed) ? parsed[0] : parsed;\n  if (!first || !first.filename) {\n    throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);\n  }\n  return first.filename;\n}\n\nasync function removeSmokeWorkspace(tempRoot, remove = fsp.rm) {\n  await remove(tempRoot, {\n    force: true,\n    recursive: true,\n    // Windows can report ENOTEMPTY briefly while completed binary downloads\n    // are still being released by the filesystem. fs.rm retries ENOTEMPTY\n    // (and the other documented transient removal errors) with linear\n    // backoff; the finite cap still surfaces a persistent cleanup failure.\n    maxRetries: CLEANUP_MAX_RETRIES,\n    retryDelay: CLEANUP_RETRY_DELAY_MS,\n  });\n}\n\nasync function main() {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/release/npm-wrapper-smoke.js#L114-L150","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Run `npm pack --json` manually in the wrapper package directory and inspect whether the output contains a `filename` field.","Upgrade or pin npm to a version whose `pack --json` output includes `filename` (npm 7+).","Check that the pack command runs in the intended package directory and not a workspace root that packs nothing."],"exampleFix":"// before\nconst first = Array.isArray(parsed) ? parsed[0] : parsed;\nif (!first || !first.filename) {\n  throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);\n}\n// after\nconst first = Array.isArray(parsed) ? parsed[0] : parsed;\nif (!first || (!first.filename && !first.name)) {\n  throw new Error(`npm pack metadata did not include a filename: ${trimmed}`);\n}\nconst filename = first.filename ?? `${first.name}-${first.version}.tgz`;","handlingStrategy":"type-guard","validationCode":"const parsed = JSON.parse(npmPackOutput);\nconst first = Array.isArray(parsed) ? parsed[0] : parsed;\nif (typeof first?.filename !== \"string\" || !first.filename) throw new Error(\"pack metadata missing filename\");","typeGuard":"function hasPackFilename(v: unknown): v is { filename: string } {\n  return typeof v === \"object\" && v !== null && typeof (v as any).filename === \"string\" && (v as any).filename.length > 0;\n}","tryCatchPattern":"try {\n  const filename = await tarball();\n} catch (err) {\n  if (String(err.message).includes(\"npm pack\")) {\n    console.error(\"Unexpected npm pack output shape; check npm version:\", err.message);\n  }\n  throw err;\n}","preventionTips":["Pin the npm version used in release CI so pack --json output shape is stable.","Smoke-test `npm pack --json` output in a tiny script after any npm upgrade.","Assert the pack output schema in CI before running the wrapper smoke test."],"tags":["npm","release","smoke-test"],"backgroundTag":"unexpected-response-shape","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}