saadeghi/daisyui · error · Error
--base-sha is required
Error message
--base-sha is required
What it means
Thrown by main() in packages/tailwind-play-share/pr-preview.mjs:573 when the parsed CLI options object has a falsy baseSha. The script is a PR-preview generator that diffs component CSS between a base and head git commit, so a base commit is mandatory to compute the before/after state. parsePreviewArgs only sets options.baseSha when the `--base-sha` flag is present and followed by a non-undefined value; any other invocation leaves it undefined and this guard rejects it before any git or browser work runs.
Source
Thrown at packages/tailwind-play-share/pr-preview.mjs:573
html: inputs.html,
})
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
- Add `--base-sha <40-char-sha>` to the command line, where the sha is the PR's merge-base or target-branch tip.
- If sourcing from CI, ensure the base SHA variable is exported (e.g. `BASE_SHA=$(git rev-parse origin/main)`) before invoking the script.
- Run with `--help` to confirm the exact flag name and required ordering.
- If scripting the call, validate the base SHA is non-empty before invoking to get a clearer upstream error.
Example fix
// before bun packages/tailwind-play-share/pr-preview.mjs --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.baseSha) {
console.error("Missing --base-sha; pass the base commit SHA (e.g. origin/main).")
process.exit(2)
}
if (!options.headSha) {
console.error("Missing --head-sha; pass the head commit SHA (e.g. HEAD).")
process.exit(2)
} Type guard
function hasBaseSha(options) {
return typeof options.baseSha === "string" && options.baseSha.length > 0
} Try / catch
try {
// ...call main / generatePrPreview with a validated baseSha
} catch (error) {
if (error.message === "--base-sha is required") {
console.error("Base SHA missing; set BASE_SHA and rerun.")
process.exit(2)
}
throw error
} Prevention
- Pin CI inputs: require base/head SHA workflow inputs with `required: true` so the job fails to start rather than failing inside the script.
- Derive SHAs from git at the call site (`git rev-parse origin/main`, `git rev-parse HEAD`) so they are never empty.
- Wrap the invocation in a shell function that asserts both SHAs are non-empty before forwarding to the .mjs file.
When it happens
Trigger: Running `bun packages/tailwind-play-share/pr-preview.mjs` without the `--base-sha <sha>` flag, or passing `--base-sha` as the last argument with no following token (in which case takeValue throws first with `--base-sha requires a value`). Also triggers if an empty string is somehow supplied, since the guard is truthiness-based (`if (!options.baseSha)`).
Common situations: CI workflow that forgot to populate the base SHA env var, a manual local invocation copied from memory without the flag, a refactor that renamed the flag, or a caller shell variable expanding to empty (e.g. `--base-sha $BASE` when BASE is unset).
Related errors
- --head-sha is required
- --timeout must be a positive number of milliseconds
- Provide HTML/CSS using arguments, files, or JSON on stdin
- html must be a string
- css must be a string
AI-assisted analysis of saadeghi/daisyui@42b09e637e (2026-08-13).
Data as JSON: /api/errors/e683e1f6c7264f5d.
Report an issue: GitHub.