Prisma Client Edge: environment variables are not working with the "new" Module Worker syntax for Cloudflare Workers
See original GitHub issueProblem
According to the recent changes in Cloudflare Workers (https://developers.cloudflare.com/workers/runtime-apis/fetch-event/) & Wrangler CLI, Environment Variables access Model, environment variables aren’t globally available anymore & in the generated edge client a Database Url is accessed through process.env.DATABASE_URL (which workers on Vercel Edge Functions) or using global. I think the Prisma Client should accept Database Url when it’s instantiated, because Different Edge Platform have their own way of accessing environment variables for example, in Netlify Edge Functions, it’s like
const db_url = Deno.env.get("DATABASE_URL");
and in Cloudflare Workers, it’s like
export default {
fetch(request, env, context) {
const db_url = env.DATABASE_URL;
},
};
or in fastly compute edge using dictionaries, it’s like
const tokens = new Dictionary("tokens");
const db_url = tokens.get("DATABASE_URL");
Suggested solution
I think Prisma Client should accept a datebase url when it’s instantiated like
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
url: "" // Pass Database Url
});
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:16 (7 by maintainers)
Top GitHub Comments
I have been using Cloudflare Workers & the new Workers Module Syntax exposes environment variables with env arguments passed to the fetch function & accessing environment variables globally is going to fail.
so, globalThis[“DATABASE_URL”] is going to fail, can you improve it, please. Thanks.
Note: the docs page https://www.prisma.io/docs/guides/deployment/deployment-guides/deploying-to-cloudflare-workers will be updated to use wrangler v2 once https://github.com/prisma/docs/pull/4014 is merged