oven-sh/bun · error

Packer template not found: ${templateFile}

Error message

Packer template not found: ${templateFile}

What it means

buildWindowsImageWithPacker() resolves scripts/packer/windows-arm64.pkr.hcl (aarch64) or windows-x64.pkr.hcl from the script's own directory and throws when existsSync fails — the checkout is missing the template or it was renamed without updating this mapping.

Source

Thrown at scripts/machine.mjs:1160

  return data.access_token;
}

/**
 * Build a Windows image using Packer (Azure only).
 * Packer handles VM creation, bootstrap, sysprep, and gallery capture via WinRM.
 * This eliminates all the Azure Run Command issues (output truncation, x64 emulation,
 * PATH not refreshing, stderr false positives, quote escaping).
 */
async function buildWindowsImageWithPacker({ os, arch, release, command, ci, agentPath, bootstrapPath }) {
  const { getSecret } = await import("./utils.mjs");

  // Determine Packer template
  const templateName = arch === "aarch64" ? "windows-arm64" : "windows-x64";
  const templateDir = resolve(import.meta.dirname, "packer");
  const templateFile = join(templateDir, `${templateName}.pkr.hcl`);

  if (!existsSync(templateFile)) {
    throw new Error(`Packer template not found: ${templateFile}`);
  }

  // Get Azure credentials from Buildkite secrets
  const clientId = await getSecret("AZURE_CLIENT_ID");
  const clientSecret = await getSecret("AZURE_CLIENT_SECRET");
  const subscriptionId = await getSecret("AZURE_SUBSCRIPTION_ID");
  const tenantId = await getSecret("AZURE_TENANT_ID");
  const resourceGroup = await getSecret("AZURE_RESOURCE_GROUP");
  const location = (await getSecret("AZURE_LOCATION")) || "eastus2";
  const galleryName = (await getSecret("AZURE_GALLERY_NAME")) || "bunCIGallery2";

  // Image naming must match getImageName() in ci.mjs:
  //   [publish images] / normal CI: "windows-x64-2019-v13"
  //   [build images]:               "windows-x64-2019-build-37194"
  const imageKey = arch === "aarch64" ? "windows-aarch64-11" : "windows-x64-2019";
  const imageDefName =
    command === "publish-image"
      ? `${imageKey}-v${getBootstrapVersion(os)}`

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Confirm the file exists: scripts/packer/windows-arm64.pkr.hcl and windows-x64.pkr.hcl
  2. `git restore scripts/packer/` if deleted, or re-clone fully
  3. If you renamed a template, update templateName/templateFile construction in machine.mjs
Defensive patterns

Strategy: validation

Validate before calling

const templateFile = join(resolve(import.meta.dirname, 'packer'), `${templateName}.pkr.hcl`);
if (!existsSync(templateFile)) {
  throw new Error(`Packer template not found: ${templateFile} — run from a full checkout of the bun repo`);
}

Prevention

When it happens

Trigger: Running machine.mjs from a partial/shallow checkout without scripts/packer; the .pkr.hcl file deleted or renamed locally; import.meta.dirname resolving somewhere unexpected after moving the script.

Common situations: Local edit renaming the template; sparse CI checkout; running a copied script outside the repo.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/ba002c2cb8fe3df3. Report an issue: GitHub.