anomalyco/sst · error · Error

Invalid artifact: ${JSON.stringify(artifact)}

Error message

Invalid artifact: ${JSON.stringify(artifact)}

What it means

The SDK release script processes goreleaser artifacts, mapping each binary artifact's goos/goarch to Node platform identifiers (windows→win32, goarch via a cpus lookup table). This error is thrown when a binary artifact's OS or CPU architecture cannot be mapped to a known npm platform, i.e. goreleaser produced a target the release script doesn't recognize.

Source

Thrown at sdk/js/scripts/release.ts:36

console.log("publishing", nextPkg.version);

await fs.rmdir("dist", { recursive: true }).catch(() => {});
await $`bun run build`;

const cpus = {
  arm64: "arm64",
  amd64: "x64",
  "386": "x86",
};

const tmp = `tmp`;
const binaryPackages = [] as string[];
for (const artifact of artifacts) {
  if (artifact.type !== "Binary") continue;
  const os = artifact.goos === "windows" ? "win32" : artifact.goos;
  const cpu = cpus[artifact.goarch as keyof typeof cpus];
  if (!os || !cpu)
    throw new Error(`Invalid artifact: ${JSON.stringify(artifact)}`);
  const name = `${pkg.name}-${os}-${cpu}`;
  const dir = path.join(tmp, name);
  const binary = path.basename(artifact.path);
  await fs.mkdir(path.join(dir, "bin"), { recursive: true });
  await fs.cp(
    path.join("../../", artifact.path),
    path.join(dir, "bin", binary),
  );
  Bun.write(
    path.join(dir, "package.json"),
    JSON.stringify(
      {
        name,
        version: nextPkg.version,
        license: nextPkg.license,
        repository: nextPkg.repository,
        os: [os],
        cpu: [cpu],

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Remove the unsupported GOOS/GOARCH target from .goreleaser.yml, or restrict builds to targets the script knows (linux/darwin/windows × amd64/arm64).
  2. Update the release script's os mapping and cpus table in sdk/js/scripts/release.ts to handle the new goos/goarch, mapping it to the matching npm platform (e.g. freebsd → 'freebsd' if publishing that package).
  3. Inspect the artifact JSON in the error message to see exactly which field is unmapped (goos vs goarch).
  4. Re-run goreleaser so artifacts.json is fresh and matches the current release config before running the script.

Example fix

// before (.goreleaser.yml)
goarch: [amd64, arm64, riscv64]
// after
goarch: [amd64, arm64]  // or add riscv64 to the cpus table in release.ts
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN_OS = new Set(["linux", "darwin", "windows"]);
const KNOWN_ARCH = new Set(["amd64", "arm64"]);
for (const a of artifacts.filter(a => a.type === "Binary")) {
  if (!KNOWN_OS.has(a.goos) || !KNOWN_ARCH.has(a.goarch))
    throw new Error(`Unmapped artifact target: ${a.goos}/${a.goarch}`);
}

Type guard

function isMappableArtifact(a: { type: string; goos: string; goarch: string }): boolean {
  return ["linux", "darwin", "windows"].includes(a.goos) && ["amd64", "arm64"].includes(a.goarch);
}

Try / catch

try {
  await runRelease(artifacts);
} catch (e) {
  if ((e as Error).message.startsWith("Invalid artifact:")) {
    console.error("Add or remove this GOOS/GOARCH target in .goreleaser.yml / release.ts mappings");
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the SDK release script (sdk/js/scripts/release.ts) with a goreleaser artifacts.json that contains a binary artifact whose goos is not windows/linux/darwin (e.g. freebsd, wasip1) or whose goarch is not in the cpus table (e.g. riscv64, loong64, mips), so `os` or `cpu` resolves to undefined.

Common situations: Adding a new GOOS/GOARCH target to .goreleaser.yml without updating the release script's mappings; goreleaser upgrading and emitting new default targets; a partially-filled or hand-edited artifacts.json; running the script against artifacts from a different project.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/388645339479e525. Report an issue: GitHub.