Running Astro project in a Worker. Local deployment not showing console.log, .warn, .info etc.
I am working on an Astro deployment into Workers. I'm trying to debug talking to a KV binding, but the console isn't showing any outputs. Here is an example of one of my pages.
---
import BaseLayout from '../layouts/BaseLayout.astro';
import Header from '../components/Header.astro';
console.log("Loading index page.");
---
<BaseLayout title="Jack Portfolio">
<Header />
<main class="d-flex flex-column align-items-center justify-content-center min-vh-100 bg-black text-white">
<img src="/images/jackhome-dark.png" alt="Jack portrait" class="img-fluid" style="max-height: 80vh; object-fit: contain;" />
</main>
</BaseLayout>
The console.log never shows any output. I've tried .log, .error, .info, .warn. I am running my development server using the following.
npx astro build
npx wrangler dev
I've tried adding --verbose to the wrangler dev command, that didn't help. I am running wrangler 4.20.5. npx version is 10.9.2.
20 Replies
Is this an SSR page? Do you have a repo?
Repo is private. What’s an SSR page?
Ahh server side, yes it’s an Astro page rendered on the server
I fixed it, my vscode config wasn't setup correctly.
I now have...
launch.json
and in my package.json
ugh, but that doesn't support debugging KV... so now if I switch to this config...
launch.json
package.json
It launches, but I am no longer able to debug or see console outputs.
so I can either debug and see console output, but not be able to interact with KV, or have KV access, but no console or debugging... eek
Is there a reason why
dev doesn't work directly?What do you mean by directly?
Nvm, just re-read your config. Assuming you are using the Cloudflare Adapter and have a relatively recent version of Astro and wrangler, you should be able to use KV in
astro dev
Any specific reason you are using pages instead of Workers?I’m using workers, it was initially a pages app but I redeployed as a worker

so you are saying I should be able to use
astro dev
instead of
wrangler dev
and still have access to the KV binding?
Because this returns null
in astro dev, but works fine in wrangler dev
Weird. Let me try spinning a new instance up and see if I see the same
It seems to be working for me? Here's my
wrangler.jsonc:
In index.astro, I do
and I see null in the logs
Via astro devHuh, lemme compare differences I a bit. On vacation
ok, I get the same. My point being, I can't access the KV when using astro dev, I need to use wrangler dev
So I can log and hit breakpoints when using astro dev, but not if I switch to wrangler dev
but I need to use wrangler dev to access KV
With the above, KV is functional, at least for me? Even with
astro dev
It’s printing null because I haven’t yet put anything in the namespacehmm strange
lemme go back and review my setup
running in astro dev,
const raw = await Astro.locals.runtime.env.PORTFOLIODATA.get("photos");
This still returns null for me, when I have JSON data in that key.
This is my debug code to try and figure out what's going wrong...
if you populate that key, can you confirm the JSON is returned?
This code also returns no keys...
Whaaat. So why is my environment not working?
Can you drop your code into a quick repo and lemme see if I can run and get the same results
Here's a repro: https://codeberg.org/AllieKat/astro-kv-test/
Codeberg.org
astro-kv-test
ok, so I cloned your repo and ran npm install. I edited the wrangler.jsonc and put in my KV id for the binding PORTFOLIODATA, replacing your "bar" placeholder. I then ran npx astro dev, and it started the site. But when I access the home page, I get...
So what I am doing wrong? What else do I need to check for this to work? I'm running the same code as you.
If I run npx astro build, I get an error on the index page.
which I assume is complaining about...
const raw = await Astro.locals.runtime.env.PORTFOLIODATA.get("photos");
doing a a list of namespaces works from the command line...
and I can list keys...
I am clearly missing an important step
Oh, you are doing remote
Doesn’t remote mean it’s using Cloudflare directly? How did you get it working?
So I need to tell Astro dev to use remote?
I don’t think Astro can use remote, that’s the issue
If you redo the command without remote, it stores the values locally/reads from the local storage
ahh i see, so I could simply inject the JSON into local storage at time of debug, test the code and then know it works on release
Gotcha, so even when using the same namespace id as the production instance, it still just stores it locally?
i'll spin up an admin page to inject the test data into storage
and it seems that local storage persists between instantiations of the astro dev server