question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Client Edge: environment variables are not working with the "new" Module Worker syntax for Cloudflare Workers

See original GitHub issue

Problem

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:open
  • Created a year ago
  • Reactions:1
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Abiti-936commented, Oct 24, 2022

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.

export default {  
  fetch(request, env, context) { 
    console.log(DATABASE_URL) // is going to fail
    console.log(env.DATABASE_URL) // works
  },
};

so, globalThis[“DATABASE_URL”] is going to fail, can you improve it, please. Thanks.

1reaction
Jolg42commented, Nov 11, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploying to Cloudflare Workers - Prisma
Today you'll be building and deploying a Cloudflare Worker that uses Prisma to save every request to a MongoDB database for inspection later....
Read more >
JavaScript modules are now supported on Cloudflare Workers
We're excited to announce that JavaScript modules are now supported on Cloudflare Workers. If you've ever taken look at an example Worker ......
Read more >
Prisma 4.2.0 Release - GitClear
fix(client): enable debug logging in edge and fix process.env access (#14537) ... the Prisma Edge Client from working with Cloudflare Module Workers.
Read more >
Discover - Remix Guide
Next.js released its new nested routes feature yesterday (Friday, 9th September). ... and even non-Node.js environments at the edge like Cloudflare Workers.
Read more >
Learn from 425 web development courses on egghead
How to work with Apollo GraphQL Client in Next.js ... And lastly, you'll learn how to deploy a Next js app to vercel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found