Repository navigation
Closed
Description
Summary of the issue
After cf dev, the --local API commands can't see the data the dev server wrote, and the local list commands can't help you find it.
- Different default state directories. In a
cf initproject,cf devpersists to./.cloudflare/state.--localcommands default to~/.config/cloudflare/state(per--help), even when run from the project directory. So without--persist-tothey read an empty store and return[]with exit 0, which looks like "no data" instead of "wrong store". - Local list commands return
[]even with the right state directory. With--persist-to ./.cloudflare/state,cf kv namespaces list --localandcf d1 list --localboth return[]. The running dev server's Local Explorer lists the namespace (CACHE-demo) and database (DB-demo), andcf kv keys list --namespace-id CACHE-demo/cf d1 raw DB-demowork once you know those IDs. The only way to find the IDs from the CLI is to guess the<BINDING>-<worker>pattern.
Command (after cf dev wrote one KV key and one D1 row) |
Result |
|---|---|
cf kv keys list --namespace-id CACHE-demo --local |
[] |
cf kv keys list --namespace-id CACHE-demo --local --persist-to .cloudflare/state |
[{"name":"hits"}] |
cf kv namespaces list --local --persist-to .cloudflare/state |
[] |
cf d1 list --local --persist-to .cloudflare/state |
[] |
GET /cdn-cgi/local/explorer/api/storage/kv/namespaces (dev server running) |
[{"id":"CACHE-demo","title":"CACHE"}] |
GET /cdn-cgi/local/explorer/api/d1/database (dev server running) |
[{"name":"DB","uuid":"DB-demo",...}] |
Expected behaviour
- Inside a project,
--localcommands use the same state directory ascf dev(or at least say which directory they read). kv namespaces list --localandd1 list --locallist the namespaces and databases in that state, using the same IDs the Local Explorer and the other--localcommands accept. If listing isn't supported in cold state, return an error instead of[]. The README says "Commands with no local explorer equivalent return an error".
Version of cf used
1.0.0-beta.12
System information and package versions
System:
OS: macOS 27.0
CPU: (18) arm64 Apple M5 Pro
Shell: 5.9 - /bin/zsh
Binaries:
Node: 26.8.2
npm: 11.19.1
npmPackages:
@cloudflare/vite-plugin: beta => 2.0.0-beta.sha-52b0dc0e9
cf: ^1.0.0-beta.12 => 1.0.0-beta.12
Reproduction (optional)
cf init demo --package-manager npm && cd democloudflare.config.ts, env:
CACHE: bindings.kv({}),
DB: bindings.d1({}),src/index.ts:
export default {
async fetch(req, env) {
const n = Number((await env.CACHE.get("hits")) ?? 0) + 1;
await env.CACHE.put("hits", String(n));
await env.DB.exec("CREATE TABLE IF NOT EXISTS visits (id INTEGER PRIMARY KEY, at TEXT)");
await env.DB.prepare("INSERT INTO visits (at) VALUES (?)").bind(new Date().toISOString()).run();
return new Response(String(n));
},
} satisfies ExportedHandler<Env>;cf dev # then curl http://localhost:5173 once, then stop it
cf kv keys list --namespace-id CACHE-demo --local # []
cf kv keys list --namespace-id CACHE-demo --local --persist-to .cloudflare/state # [{"name":"hits"}]
cf kv namespaces list --local --persist-to .cloudflare/state # []
cf d1 list --local --persist-to .cloudflare/state # []Relevant error logs (optional)
None. Every command exits 0. Related: #22 notes that --local and wrangler dev also default to different directories.
Reacted by Aidan Gallagher and hoshikawa
Metadata
Metadata
Assignees
Labels
No labels
Activity