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.

Root `.env` variables aren't available to prisma in monorepo

See original GitHub issue

Bug description

We have a monorepo using turbo repo with the following structure:

image

The prisma package is being used in multiple applications, currently we’re trying to use a single .env to avoid confusion. Moving the DATABASE_URL url from packages/prisma/.env to the root .env errors when trying to run any yarn prisma script.

We also tried to use a solution like cmd-env:

image

But no luck so far.

image

How to reproduce

  1. Have a monorepo with and .env file at the root
  2. Have something like packages/prisma in a monorepo package
  3. Set DATABASE_URL in the root .env file.
  4. Try to run any yarn prisma command.

Expected behavior

Being able to use the monorepo DATABASE_URL without having to set it up in packages/prisma/.env.

Prisma information

https://github.com/calcom/cal.com/blob/main/packages/prisma/schema.prisma

Environment & setup

  • OS: Mac OS 12
  • Database: PostgreSQL
  • Node.js version: v14.17.6

Prisma Version


prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

2reactions
zomarscommented, Aug 1, 2022

Related example: https://github.com/vercel/turborepo/tree/main/examples/with-prisma

Awesome @leerob although I see you’re using symlinks to fix the “.env not it prisma root” problem. The thing is we only use this locally since we don’t actually deploy .env files to prod. Wouldn’t this approach break in prod in this case?

1reaction
leerobcommented, Aug 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variables - Prisma
Learn how to use environment variables in your Prisma project. ... Prisma creates a default .env file at your projects root. You can...
Read more >
prisma - getting environment variable not found error message ...
If anybody running into this issue, just run npx prisma generate . This will re-establish the link between schema.prisma and .env file.
Read more >
Using Prisma with Turborepo
Set up Prisma in a monorepo; Handle migration and code generation ... If you're using pnpm , you should add a file at...
Read more >
Managing multiple environments in NestJS
Create the following structure in the root of your NestJS app. ... Another benefit is to provide defaults in case the env variables...
Read more >
Building an Nx Prisma Generator - Sabin Adams - Hashnode
We will be able to access the Prisma Client using something like: ... generated variable in a .env file that all prisma schemas...
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