{"record":{"id":"6deb6969d2210349","repo":"anomalyco/sst","slug":"failed-to-decode-cloudflare-unenv-config-w-s","errorCode":null,"errorMessage":"failed to decode cloudflare unenv config: %w\n%s","messagePattern":"failed to decode cloudflare unenv config: %w\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/worker/worker.go","lineNumber":266,"sourceCode":"\t}\n\tw.lock.RUnlock()\n\n\tcmd := process.CommandContext(\n\t\tctx,\n\t\t\"node\",\n\t\tfilepath.Join(path.ResolvePlatformDir(cfgPath), \"src/runtime/worker/unenv.mjs\"),\n\t\tstring(payload),\n\t)\n\tcmd.Dir = path.ResolvePlatformDir(cfgPath)\n\tcmd.Env = []string{}\n\toutput, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load cloudflare unenv config: %w\\n%s\", err, output)\n\t}\n\n\tvar result unenv\n\tif err := json.Unmarshal(output, &result); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode cloudflare unenv config: %w\\n%s\", err, output)\n\t}\n\n\tw.lock.Lock()\n\tw.unenv[key] = &result\n\tw.lock.Unlock()\n\n\treturn &result, nil\n}\n\nfunc (w *Runtime) Match(runtime string) bool {\n\treturn runtime == \"worker\"\n}\n\nfunc (w *Runtime) getFile(input *runtime.BuildInput) (string, bool) {\n\tdir := filepath.Dir(input.Handler)\n\tbase := strings.Split(filepath.Base(input.Handler), \".\")[0]\n\tfor _, ext := range node.NODE_EXTENSIONS {\n\t\tfile := filepath.Join(path.ResolveRootDir(input.CfgPath), dir, base+ext)","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/worker/worker.go#L248-L284","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// sanity-check that unenv.mjs emits pure JSON before deploying\nconst { execSync } = require(\"child_process\");\nconst out = execSync(\"node .sst/platform/src/runtime/worker/unenv.mjs '{}'\").toString();\nJSON.parse(out); // throws if extra non-JSON output pollutes stdout","typeGuard":null,"tryCatchPattern":"try {\n  await run(\"sst\", [\"deploy\"]);\n} catch (e) {\n  if (/failed to decode cloudflare unenv config/.test(String(e))) {\n    console.error(\"unenv.mjs output was not JSON. Reinstall .sst/platform to match your SST CLI version.\");\n  } else throw e;\n}","preventionTips":["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"],"tags":["worker","cloudflare","json","build","subprocess"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}