Vercel build fails with monorepo: `Error: [Upstash Redis] The 'url' property is missing or undefined in your Redis config.`
I just abstracted @vercel/kv into a Turborepo package to use a shared client between my apps using createClient. My local builds are fine but on Vercel my build fails with the error in the title. Here's my client creation code:
import { createClient } from "@vercel/kv";
export const kv = createClient({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
});
My environment variables are stored in the root .env file.
These logs came from a failed Dependency Function using KV and os.getenv. There seems to be a problem with the Internal Environment Reading
(venv) ec2-user:~/environment/myapp $ python -m uvicorn api.index:app --host 0.0.0.0 --port 8080
INFO: Started server process [46913]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
INFO: <my-ip>- "GET /api HTTP/1.1" 200 OK
ERROR: Failed to instantiate KV client with explicit args: __init__() got an unexpected keyword argument 'url'
INFO: <my-ip> - "GET /api/book/call_function/1.1" 500 Internal Server Error
INFO: <my-ip> - "GET /DOCS HTTP/1.1" 404 Not Found
INFO: <my-ip> - "GET /docs HTTP/1.1" 200 OK
INFO: <my-ip> - "GET /openapi.json HTTP/1.1" 200 OK
The vercel-kv Library Issue
The vercel-kv library's KV() constructor is somehow not using os.getenv in a way that sees the current state of the environment as modified by load_dotenv(). It might be reading the environment before load_dotenv has its full effect within that process context, or it might be using a different mechanism entirely that isn't picking up the loaded variables.
This is a significant inconsistency or bug in how the vercel-kv Python library I've been trying to use handles environment variables during instantiation:
- It does not accept configuration via constructor arguments.
- Its internal mechanism for reading environment variables fails intermittently or is incompatible with how python-dotenv modifies the environment in the context of Uvicorn/FastAPI dependency injection.
This seems like a potential bug or unexpected behavior within the vercel-kv library, especially concerning its interaction with python-dotenv.
I see documentation for vercel-kv library has been removed and plan to try upstash.