saadeghi/daisyui · error · Error

html must be a string

Error message

html must be a string

What it means

After resolving, if html is defined (not undefined) but typeof html is not 'string', the script throws. This catches malformed JSON where the html field is a number, array, object, or null (null is not undefined, so it triggers this branch).

Source

Thrown at packages/tailwind-play-share/index.mjs:167

  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 ?? "" }
}

async function isExecutable(filePath) {
  try {
    await access(filePath, process.platform === "win32" ? fsConstants.F_OK : fsConstants.X_OK)
    return true
  } catch {
    return false
  }
}

async function resolveExecutable(candidate) {

View on GitHub (pinned to 42b09e637e)

Solutions

  1. Ensure the html field is a JSON string.
  2. Omit the html key entirely if you have no HTML (so it stays undefined).
  3. Coerce to string in your producer before serializing.

Example fix

# before
echo '{"html":["<div/>"]}' | bun .../index.mjs
# after
echo '{"html":"<div/>"}' | bun .../index.mjs
Defensive patterns

Strategy: type-guard

Validate before calling

if (html !== undefined && typeof html !== 'string') {
  throw new Error('html must be a string')
}

Type guard

const isOptionalString = (v) => v === undefined || typeof v === 'string'

Prevention

When it happens

Trigger: Piping JSON like `{"html":123}`, `{"html":["..."]}`, `{"html":{"raw":"..."}}`, or `{"html":null}`.

Common situations: A programmatic producer emits the wrong type; a YAML-to-JSON conversion yields a non-string; null used to mean 'absent'.

Related errors


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