remix icon indicating copy to clipboard operation
remix copied to clipboard

Remix + Cloudflare Pages + Prisma - Cannot read datasource from environment variable

Open inssein opened this issue 3 years ago • 1 comments

What version of Remix are you using?

1.7.5

Steps to Reproduce

Start a new base project with remix + cloudflare, and add prisma.

This bug is related to https://github.com/prisma/prisma/issues/15958 on the prisma end.

While this bug seems mostly on the prisma end, I feel like there will be some wiring up needed on the remix end when creating the cloudflare pages handler.

Expected Behavior

Prisma should be able to initialize a datasource from the DATABASE_URL env variable

Actual Behavior

ReferenceError: DATABASE_URL is not defined.
Attempted to access binding using global in modules.
You must use the 2nd `env` parameter passed to exported handlers/Durable Object constructors, or `context.env` with Pages Functions.

inssein avatar Nov 06 '22 20:11 inssein

Also hit this issue, it's due to the new module syntax for workers/pages. I unblocked myself by shifting to use Remix's cloudflare worker setup instead since that one still uses the older non-module syntax which is supported by Prisma out of the box.

craigsc avatar Nov 11 '22 04:11 craigsc

See also https://community.cloudflare.com/t/how-to-access-environment-variables-from-libraries/480041

tsteckenborn avatar Mar 20 '23 08:03 tsteckenborn