workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: `wrangler dev -l` doesn't use preview KV namespace

Open andogq opened this issue 2 years ago • 3 comments

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.

andogq avatar Jul 20 '22 12:07 andogq

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.

threepointone avatar Jul 20 '22 13:07 threepointone

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.

andogq avatar Jul 20 '22 13:07 andogq

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.

ni554n avatar Aug 05 '22 20:08 ni554n

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

JacobMGEvans avatar Aug 15 '22 16:08 JacobMGEvans

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 the wrangler-local-state subdirectory.

Screenshot 2022-08-17 at 15 01 19

penalosa avatar Aug 17 '22 14:08 penalosa

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 the wrangler-local-state subdirectory.

Screenshot 2022-08-17 at 15 01 19

@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.

JacobMGEvans avatar Aug 17 '22 15:08 JacobMGEvans