Ran wrangler dev
and it doesn't seem to bind Worker KV:
ERROR in /src/handler.ts
./src/handler.ts 16:8-17
[tsl] ERROR in /src/handler.ts(16,9)
TS2304: Cannot find name 'generalKV'.
Here is 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);
}
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 suggests change kv_namespaces
to kv-namespaces
, but it doesn't work for me. Please inform me if I missed anything else.
generalKV
to be available at runtime, so that it doesn't complain about it being undefined during compilation. – HaversackgeneralKV
to be available, since the documents says a global variable will be created after binding. – Watch