After running wrangler dev
, it appears that Worker KV is not being bound properly:
ERROR in /src/handler.ts
./src/handler.ts 16:8-17
[tsl] ERROR in /src/handler.ts(16,9)
TS2304: Cannot find name 'generalKV'.
This is the content of handler.ts
:
async function postHandler(request: Request): Promise<Response> {
let content = JSON.stringify(await request.json());
await generalKV.put([Date.now().toString()], JSON.stringify(content));
return new Response(content);
}
Contents of wrangler.toml
:
name = "general-assignment"
type = "javascript"
account_id = "<id>"
workers_dev = true
compatibility_date = "2021-11-01"
kv_namespaces = [
{ binding = "generalKV", id = "<id>", preview_id = "<id>" }
]
Some have suggested changing kv_namespaces
to kv-namespaces
, but this solution did not work for me. Please advise if there are any other steps I may have missed.