Just spent an hour debugging why my D1 database binding wasn't working. Here's what happened and what I learned:
Symptoms I saw:
- Bindings were not showing in the dashboard after
wrangler deploy - Even after adding the binding manually in Settings → they didn't appear
- Settings page showed: "Variables cannot be added to a Worker that only has static assets."
- Everything worked fine when I had the code in the Worker directly, but after switching to GitHub + wrangler.jsonc, my database stopped storing items
Root cause:
I had "assets": { "directory": "." } without a proper Worker entrypoint.
Solution:
You need both:
{
"main": "../src/index.js", // ← Relative to wrangler.jsonc location!
"assets": {
"directory": ".",
"binding": "ASSETS"
}
}
Plus your regular bindings (D1, KV, etc.).
Moral of the story:
When combining static assets with dynamic logic (like a database), make sure you define a main script and properly bind the ASSETS. The dashboard can be misleading when things are partially configured.
Has anyone else hit this specific combo of issues? Especially after moving from dashboard-only to GitHub + Wrangler?
