anomalyco/sst · error
failed to load cloudflare unenv config: %w %s
Error message
failed to load cloudflare unenv config: %w %s
What it means
The worker (Cloudflare Workers) runtime determines Node.js compat polyfills by spawning `node src/runtime/worker/unenv.mjs` with the project's compatibility flags. This error means the child Node process exited non-zero; the script's combined stdout/stderr is appended to help diagnose why. unenv config resolution is required before esbuild can bundle, so the build aborts.
Source
Thrown at pkg/runtime/worker/worker.go:261
w.lock.RLock()
if cached, ok := w.unenv[key]; ok {
w.lock.RUnlock()
return cached, nil
}
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"
}
View on GitHub (pinned to a0bd20f762)
Solutions
- Ensure `node` (>=18) is installed and on PATH: `node -v`
- Delete `.sst/` and reinstall platform deps (`bun install` / `npm install` in the platform dir), then retry
- Check your `worker` component's `compatibilityDate`/`compatibilityFlags` values against valid Cloudflare dates
- Run the script manually to see the full error: `cd .sst/platform/src/runtime/worker && node unenv.mjs '{}'`
Example fix
// before (sst.config.ts) compatibilityDate: "2099-01-01" // after compatibilityDate: "2025-01-01"
Defensive patterns
Strategy: try-catch
Validate before calling
// before deploy, ensure node is available and the platform script exists
execSync("node -v", { stdio: "inherit" });
const script = path.join(".sst/platform/src/runtime/worker/unenv.mjs");
if (!fs.existsSync(script)) throw new Error("platform not installed; run sst setup / reinstall"); Try / catch
try {
await run("sst", ["deploy"]);
} catch (e) {
if (/failed to load cloudflare unenv config/.test(String(e))) {
console.error("unenv.mjs failed; output was:\n" + String(e).split("\n").slice(1).join("\n"));
// common remedy: reinstall platform deps
await exec("rm", ["-rf", ".sst"]);
await run("sst", ["deploy"]); // or instruct user to reinstall
} else throw e;
} Prevention
- Keep Node.js >= 18 on PATH in dev and CI
- Never hand-edit `.sst/platform` scripts; reinstall platform artifacts after SST upgrades
- Validate compatibilityDate/compatibilityFlags values before deploy
- Ensure a clean, complete `npm install`/`bun install` of platform dependencies
When it happens
Trigger: Running `sst deploy`/`sst dev` for a `worker` runtime component when the spawned `node unenv.mjs` fails: node not on PATH, the script throws (missing `unenv` dependency in the platform dir), or an invalid `compatibility_date`/`compatibility_flags` payload.
Common situations: No Node.js installed or wrong version on the machine; corrupted or partially installed `node_modules` under `.sst/platform`; unsupported compatibility date string passed in `sst.config.ts`; empty `cmd.Env` hiding needed env vars.
Related errors
- failed to decode cloudflare unenv config: %w %s
- Invalid worker definition for the "${name}" Worker
- not implemented
- Build metadata file not found at "${filePath}". Update your
- Build ID not found in ".next/BUILD_ID" for site "${name}". E
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/cfc552c9593a6b09.
Report an issue: GitHub.