Hyperdrive fails to connect in `scheduled()` (but works over HTTP)

The same worker either will or won't connect to my Hyperdrive DB depending on whether I invoke it over HTTP (will) or CRON( won't). I'm experiencing this while testing locally, with the
--remote
flag enabled.

Specifically, I get:
DB ERROR TypeError: Cannot read properties of undefined (reading 'connectionString')

In my DB handler, I put the following:
console.log(env.db?.connectionString)

Over HTTP, I get:
postgresql://********:******…/**********?sslmode=disable

Over CRON, I get (via the --test-scheduled flag and the /__scheduled endpoint):
undefined

Accordingly, DB queries work over HTTP but I get errors on CRON. Here's how I specify my DB in dev.toml:
hyperdrive = [
    { binding = "db", id = "5e1*************", localConnectionString = "postgresql://***************" }
]

Here's what runs when I run npm run dev:
wrangler dev --config "dev.toml" --remote --port 1933 --env dev --test-scheduled

Here's what then comes up (see image below). As you can see, my Hyperdrive DB is there.

Any help appreciated
image.png
Was this page helpful?