saadeghi/daisyui · error · Error

${stderr}

Error message

${stderr}

What it means

runInCwd spawns `bun --eval <code>` in the given cwd and re-throws the child's stderr verbatim when the subprocess exits non-zero. It is a daisyUI test helper used to assert runtime behaviour of generated plugin code in an isolated working directory. The thrown message is the child process's own diagnostic, not a fixed string.

Source

Thrown at packages/daisyui/functions/testUtils.js:26

  return {
    make: async () => {
      const dir = await mkdtemp(join(tmpdir(), prefix))
      dirs.push(dir)
      return dir
    },
    cleanup: async () => {
      await Promise.all(dirs.map((dir) => rm(dir, { recursive: true, force: true })))
      dirs = []
    },
  }
}

export const runInCwd = async (cwd, code) => {
  const proc = Bun.spawn(["bun", "--eval", code], { cwd, stderr: "pipe" })
  const [exitCode, stderr] = await Promise.all([proc.exited, new Response(proc.stderr).text()])

  if (exitCode !== 0) {
    throw new Error(stderr)
  }
}

View on GitHub (pinned to 42b09e637e)

Solutions

  1. Read the thrown stderr verbatim - it is the actual failing line/stack from the child.
  2. Reproduce by hand: run `bun --eval "<code>"` from the same cwd the test used.
  3. Fix the eval code or ensure the cwd has the modules/paths it imports.
  4. If the spawn itself failed, confirm `bun` is on PATH in the test environment.

Example fix

// before: eval code imports a path that only resolves from the test file dir
await runInCwd(tmpDir, `import x from "./helper.js"`)
// after: use an absolute path or copy the helper into tmpDir first
await runInCwd(tmpDir, `import x from "${JSON.stringify(helperAbsPath)}"`)
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the eval code parses before spawning a child.
import { parse } from "node:path"
async function safeRunInCwd(cwd, code) {
  // Cheap parse check so a SyntaxError surfaces here, not as opaque stderr.
  new Bun.Transpiler({}).transform(code) // throws on syntax error
  return runInCwd(cwd, code)
}

Type guard

// Confirm cwd is an existing directory before running.
import { stat } from "node:fs/promises"
const isDir = async (p) => { try { return (await stat(p)).isDirectory() } catch { return false } }

Try / catch

try {
  await runInCwd(tmpDir, code)
} catch (error) {
  // error.message is the child's stderr; assert on it for negative tests.
  if (!/expected pattern/.test(error.message)) throw error
}

Prevention

When it happens

Trigger: Calling runInCwd(cwd, code) where the eval'd code throws at runtime, has a syntax error, references an import that does not resolve in cwd, or where `bun` is not on PATH so the spawn fails.

Common situations: Test eval code that imports a module missing from the temp cwd; a relative import path that is wrong once Bun runs from cwd instead of the test file's directory; Bun version mismatch producing a different runtime error.

Related errors


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