workers-sdk
workers-sdk copied to clipboard
🐛 BUG: `wrangler dev -l` doesn't use preview KV namespace
What version of Wrangler
are you using?
2.0.22
What operating system are you using?
Mac
Describe the Bug
When running wrangler dev -l
the KV store for a namespace will remain empty, despite data being present (added via wrangler kv:key put --binding=domains --preview true "key" "value"
). Running wrangler kv:key list --binding=domains --preview true
does return the key, however listing the keys from within the worker, or attempting to retrieve the key returns nothing.
wrangler lists the preview namespace id as an available binding when starting.
Turning off local mode restores expected functionality, and uses the preview namespace as expected, so it appears to be only a problem when running with the -l
flag.
This is as expected, but I can see why this is confusing. In local mode, the worker uses a fully local version of the kv store (powered by miniflare) and does not bind to the actual kv store on the edge, preview or otherwise.
I presumed as much. Might be worth a clarification in the docs (if I didn't already miss it) - even if it's just pointing users towards Miniflare when they're running local mode.
This is exactly what I thought after I updated my project from 0.0.19 to 2.0.24.
Wrangler was implicitly reading KVs from .mf/
folder that I was generating using Miniflare. But after the update, it was no longer the case.
Cloudflare doc didn't mention anything about the ephemeral nature of --local
flag in pages dev command, which is set to true by default.
A single mention of --experimental-enable-local-persistence
flag with wrangler-local-state
folder could have saved much time.
I presumed as much. Might be worth a clarification in the docs (if I didn't already miss it) - even if it's just pointing users towards Miniflare when they're running local mode.
Quick win: improve documentation around utilizing Miniflare when in --local
mode and the --experimental-enable-local-persistence
This is probably more a change for the cloudflare/cloudflare-docs repo—how does this language sound?
This runs an ephemeral local version of your worker, and will not be able to access data stored on Cloudflare's edge (for instance, this includes your KV stores). If you'd like to persist data locally, the experimental option
--experimental-enable-local-persistence
will store data in thewrangler-local-state
subdirectory.
This is probably more a change for the cloudflare/cloudflare-docs repo—how does this language sound?
This runs an ephemeral local version of your worker, and will not be able to access data stored on Cloudflare's edge (for instance, this includes your KV stores). If you'd like to persist data locally, the experimental option
--experimental-enable-local-persistence
will store data in thewrangler-local-state
subdirectory.
@penalosa Correct it is, I should be more clear which documentation next time. This is looking good, the technical writer team will follow up on the PR you make too.