saadeghi/daisyui · error · Error

--head-sha is required

Error message

--head-sha is required

What it means

Thrown by main() in packages/tailwind-play-share/pr-preview.mjs:574 when the parsed CLI options object has a falsy headSha. The generator reads changed component CSS at the head commit and renders it in Tailwind Play, so a head commit identifier is required. parsePreviewArgs only sets options.headSha when the `--head-sha` flag is supplied with a value; otherwise it stays undefined and this guard fails fast before any diffing or browser launch.

Source

Thrown at packages/tailwind-play-share/pr-preview.mjs:574

  })

  return {
    afterUrl,
    beforeUrl,
    components: inputs.components,
    docsPages: inputs.docsPages,
    headSha,
  }
}

async function main() {
  const options = parsePreviewArgs(process.argv.slice(2))
  if (options.help) {
    console.log(usage)
    return
  }
  if (!options.baseSha) throw new Error("--base-sha is required")
  if (!options.headSha) throw new Error("--head-sha is required")
  if (!options.output) throw new Error("--output is required")

  const preview = await generatePrPreview(options)
  await writeFile(resolve(options.output), `${JSON.stringify(preview, null, 2)}\n`)
}

const isMain =
  process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href

if (isMain) {
  main().catch((error) => {
    console.error(`tailwind-play-pr-preview: ${error.message}`)
    process.exitCode = 1
  })
}

View on GitHub (pinned to 42b09e637e)

Solutions

  1. Add `--head-sha <40-char-sha>` (the PR's latest commit) to the command line.
  2. In GitHub Actions, gate the step on `github.event_name == 'pull_request'` and use `github.event.pull_request.head.sha`.
  3. If invoking locally, export HEAD_SHA from `git rev-parse HEAD` and pass `--head-sha "$HEAD_SHA"`.
  4. Run with `--help` to verify flag spelling and argument order.

Example fix

// before
bun packages/tailwind-play-share/pr-preview.mjs --base-sha "$BASE_SHA" --output preview.json
// after
bun packages/tailwind-play-share/pr-preview.mjs --base-sha "$BASE_SHA" --head-sha "$HEAD_SHA" --output preview.json
Defensive patterns

Strategy: validation

Validate before calling

import { parsePreviewArgs } from "./packages/tailwind-play-share/pr-preview.mjs"

const options = parsePreviewArgs(argv)
if (!options.headSha) {
  console.error("Missing --head-sha; pass the head commit SHA (e.g. HEAD).")
  process.exit(2)
}

Type guard

function hasHeadSha(options) {
  return typeof options.headSha === "string" && options.headSha.length > 0
}

Try / catch

try {
  // ...call main / generatePrPreview with a validated headSha
} catch (error) {
  if (error.message === "--head-sha is required") {
    console.error("Head SHA missing; pass --head-sha with the PR commit.")
    process.exit(2)
  }
  throw error
}

Prevention

When it happens

Trigger: Invoking the script without the `--head-sha <sha>` flag, or with `--head-sha` as the final token (caught earlier by takeValue as `--head-sha requires a value`). An empty-string value would also trip the truthiness check.

Common situations: CI job missing the PR head SHA input, a local test run that only set the base sha, a GitHub Actions step where `github.event.pull_request.head.sha` was referenced in a non-Pull Request event (so it is empty), or a typo'd flag name like `--head_sha` or `--head`.

Related errors


AI-assisted analysis of saadeghi/daisyui@42b09e637e (2026-08-13). Data as JSON: /api/errors/b278ebf066214281. Report an issue: GitHub.