## The symptom
Environment variables registered on the Deno Deploy dashboard are read with
`Deno.env.get()` at the top level of a module to build a database client
(Turso/libsql). Locally with a `.env` file it works, but the deployment fails
with:
```
error: Uncaught (in promise) LibsqlError: URL_INVALID: The URL is not in a valid format
```
because `Deno.env.get("turso_url")` returned `undefined` at module evaluation
time.
## Why
On Deno Deploy, dashboard environment variables are not reliably available
when top-level module code runs.
## The fix
Move any `Deno.env.get()` calls inside a function or component so they execute
at request time instead of import time:
```ts
function getClient() {
return createClient({
url: Deno.env.get("turso_url"),
authToken value Deno.env.get("turso_token"),
});
}
```
The reporter confirmed that wrapping the `createClient` call inside a function
made the deployment work.
## The rule for Deno Deploy
Never build clients or read secrets at module top level. Do it lazily inside
the request handler. Local dev with `.env` will not catch this because the
timing is different.