anomalyco/sst · error
failed to decode cloudflare unenv config: %w %s
Error message
failed to decode cloudflare unenv config: %w %s
What it means
After the `unenv.mjs` Node script runs successfully, SST parses its stdout as JSON into the `unenv` struct. This error means the process exited 0 but its output was not valid JSON of the expected shape, so the polyfill config cannot be used for bundling.
Source
Thrown at pkg/runtime/worker/worker.go:266
}
w.lock.RUnlock()
cmd := process.CommandContext(
ctx,
"node",
filepath.Join(path.ResolvePlatformDir(cfgPath), "src/runtime/worker/unenv.mjs"),
string(payload),
)
cmd.Dir = path.ResolvePlatformDir(cfgPath)
cmd.Env = []string{}
output, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to load cloudflare unenv config: %w\n%s", err, output)
}
var result unenv
if err := json.Unmarshal(output, &result); err != nil {
return nil, fmt.Errorf("failed to decode cloudflare unenv config: %w\n%s", err, output)
}
w.lock.Lock()
w.unenv[key] = &result
w.lock.Unlock()
return &result, nil
}
func (w *Runtime) Match(runtime string) bool {
return runtime == "worker"
}
func (w *Runtime) getFile(input *runtime.BuildInput) (string, bool) {
dir := filepath.Dir(input.Handler)
base := strings.Split(filepath.Base(input.Handler), ".")[0]
for _, ext := range node.NODE_EXTENSIONS {
file := filepath.Join(path.ResolveRootDir(input.CfgPath), dir, base+ext)View on GitHub (pinned to a0bd20f762)
Solutions
- Run `bun run setup` / reinstall so `.sst/platform` matches your SST CLI version, then retry
- Remove `.sst/` directory and rebuild to clear stale platform artifacts
- Patch or silence any extra console output in unenv.mjs so stdout contains only JSON
- Pin a single SST version across CI and local machines
Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check that unenv.mjs emits pure JSON before deploying
const { execSync } = require("child_process");
const out = execSync("node .sst/platform/src/runtime/worker/unenv.mjs '{}'").toString();
JSON.parse(out); // throws if extra non-JSON output pollutes stdout Try / catch
try {
await run("sst", ["deploy"]);
} catch (e) {
if (/failed to decode cloudflare unenv config/.test(String(e))) {
console.error("unenv.mjs output was not JSON. Reinstall .sst/platform to match your SST CLI version.");
} else throw e;
} Prevention
- Keep the SST CLI and `.sst/platform` artifacts at the same version
- Remove any console.log/warning output from unenv.mjs that would corrupt stdout JSON
- Pin SST versions across machines and CI to avoid schema drift
- Wipe `.sst/` after upgrades and let it regenerate
When it happens
Trigger: `json.Unmarshal(output, &result)` fails in `getUnenv` — e.g. unenv.mjs printed a warning/extra text before the JSON, an older platform script emitted a different schema, or the process was truncated.
Common situations: Out-of-sync `.sst/platform` (old unenv.mjs with new CLI or vice versa); npm update banners or noisy console.log injected into stdout; manually patched platform scripts; mixed SST version artifacts after an upgrade.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to load cloudflare unenv config: %w %s
- Invalid worker definition for the "${name}" Worker
- failed to parse properties: %w
- not implemented
- failed to parse API response: %v
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/6deb6969d2210349.
Report an issue: GitHub.