saadeghi/daisyui · error · Error
stdin must be JSON with html and css strings: ${error.messag
Error message
stdin must be JSON with html and css strings: ${error.message} What it means
When stdin is not a TTY and html/css are still undefined, the script reads stdin, trims it, and tries JSON.parse. If parse throws, it re-throws with the parser's error message attached. The expected shape is an object with html and css string fields.
Source
Thrown at packages/tailwind-play-share/index.mjs:156
async function resolveInput(options) {
let html = options.html
let css = options.css
if (options.htmlFile !== undefined) {
html = await readFile(resolve(options.htmlFile), "utf8")
}
if (options.cssFile !== undefined) {
css = await readFile(resolve(options.cssFile), "utf8")
}
if (html === undefined && css === undefined && !process.stdin.isTTY) {
const stdin = (await readStdin()).trim()
if (stdin) {
let parsed
try {
parsed = JSON.parse(stdin)
} catch (error) {
throw new Error(`stdin must be JSON with html and css strings: ${error.message}`)
}
html = parsed.html
css = parsed.css
}
}
if (html === undefined && css === undefined) {
throw new Error("Provide HTML/CSS using arguments, files, or JSON on stdin")
}
if (html !== undefined && typeof html !== "string") {
throw new Error("html must be a string")
}
if (css !== undefined && typeof css !== "string") {
throw new Error("css must be a string")
}
return { html: html ?? "", css: css ?? "" }
}View on GitHub (pinned to 42b09e637e)
Solutions
- Pipe a valid JSON object: `{"html":"...","css":"..."}`.
- Strip any prefix/suffix lines around the JSON before piping.
- If you only have raw text, use --html/--css or --html-file/--css-file instead of stdin.
Example fix
# before
echo '<div>hi</div>' | bun .../index.mjs
# after
echo '{"html":"<div>hi</div>","css":""}' | bun .../index.mjs Defensive patterns
Strategy: try-catch
Validate before calling
function tryParseJson(stdin) {
try { return JSON.parse(stdin) } catch { return undefined }
} Type guard
const looksLikeJson = (s) => { const t = s.trim(); return t.startsWith('{') && t.endsWith('}') } Try / catch
try {
parsed = JSON.parse(stdin)
} catch (error) {
throw new Error(`stdin must be JSON with html and css strings: ${error.message}`)
} Prevention
- Always wrap stdin payloads as {"html":"...","css":"..."}.
- Strip log/timestamp lines before the JSON when piping from CI.
- Prefer --html/--css for raw text to avoid JSON escaping pitfalls.
When it happens
Trigger: Piping non-JSON text (raw HTML, CSS, or prose); malformed JSON (trailing comma, single quotes, unquoted keys); a leading BOM or log prefix before the JSON.
Common situations: echo'ing HTML directly into the pipe without wrapping in JSON; a CI step that prepends a timestamp line; JSON produced by a tool that emits comments.
Related errors
- html must be a string
- css must be a string
- ${flag} requires a value
- Unknown option: ${argument}
- Too many positional arguments
AI-assisted analysis of saadeghi/daisyui@42b09e637e (2026-08-13).
Data as JSON: /api/errors/6f9bac95ab0cc187.
Report an issue: GitHub.