wrangler ignores KV bindings in config

I've used the following in my wrangler.toml:
kv_namespaces = [
{ binding = "BROWSER_SCREENSHOT_CACHE", id = "xxx" }
]
kv_namespaces = [
{ binding = "BROWSER_SCREENSHOT_CACHE", id = "xxx" }
]
. However, once I deploy the worker, the KV binding gets removed and is no longer available in the code and not visible in the dashboard as binded. However, I can add it in the dashboard and it works thinkies the wrangler.toml code by the dash doesn't change anything, it's the same)
7 Replies
Tin Cap
Tin Cap•11mo ago
Any chance you have different configuration parameters for different environments?
TomatoCake
TomatoCake•11mo ago
not sure what you mean I only use prod rn, no staging/dev
kian
kian•11mo ago
What's your full wrangler.toml?
TomatoCake
TomatoCake•11mo ago
name = "browser-screenshot"
main = "src/worker.js"
compatibility_date = "2023-07-25"
compatibility_flags = [ "nodejs_compat" ]

[placement]
mode = "smart"

browser = { binding = "MYBROWSER", type = "browser" }
kv_namespaces = [
{ binding = "BROWSER_SCREENSHOT_CACHE", id = "xxx" }
]
name = "browser-screenshot"
main = "src/worker.js"
compatibility_date = "2023-07-25"
compatibility_flags = [ "nodejs_compat" ]

[placement]
mode = "smart"

browser = { binding = "MYBROWSER", type = "browser" }
kv_namespaces = [
{ binding = "BROWSER_SCREENSHOT_CACHE", id = "xxx" }
]
(is the kv id something i have to censor?)
kian
kian•11mo ago
Nope, but you need to move stuff above [placement] or change it to be tables as well.
name = "browser-screenshot"
main = "src/worker.js"
compatibility_date = "2023-07-25"
compatibility_flags = [ "nodejs_compat" ]

[placement]
mode = "smart"

[browser]
binding = "MYBROWSER"

[[kv_namespaces]]
binding = "BROWSER_SCREENSHOT_CACHE"
id = "xxx"
name = "browser-screenshot"
main = "src/worker.js"
compatibility_date = "2023-07-25"
compatibility_flags = [ "nodejs_compat" ]

[placement]
mode = "smart"

[browser]
binding = "MYBROWSER"

[[kv_namespaces]]
binding = "BROWSER_SCREENSHOT_CACHE"
id = "xxx"
Basically, since you defined a table ([placement]) then anything under that until another table or EOF, is under the [placement] table. You basically defined placement.browser & placement.kv_namespaces, rather than having top-level browser and kv_namespaces keys. Using tables ([browser] and [[kv_namespaces]]) avoids that. If you don't want to use tables for those, just move the browser and kv_namespaces lines above [placement]
TomatoCake
TomatoCake•11mo ago
oh never used toml before xD ty
Tin Cap
Tin Cap•11mo ago
toml is a silly format IMO 😛