Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zomars opened this issue Mar 25, 2022 · 8 comments
Open

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

zomars opened this issue Mar 25, 2022 · 8 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: .env topic: monorepo topic: turborepo https://turborepo.org/

Comments

@zomars
Copy link

zomars commented Mar 25, 2022

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
@zomars zomars added the kind/bug A reported bug. label Mar 25, 2022
@janpio janpio added topic: monorepo topic: .env team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Mar 25, 2022
@altano
Copy link

altano commented Apr 12, 2022

I can reproduce your original issue but npm + env-cmd seem to work for me, with either:

  • Directly running npm exec --workspace @mypkg/prisma -- env-cmd -f ../../.env prisma db push
  • Or, a package.json script (in the prisma pkg) e.g. "face": "env-cmd -f ../../.env prisma db push" and then running npm run --workspace @mypkg/prisma face from the root

This is gross though, either way. Would be nice to be able to configure prisma and tell it where to find the .env file, since the current options don't work great for a monorepo, as you said.

@altano
Copy link

altano commented Apr 12, 2022

FWIW dotenv-cli also worked for me. My package.json script is:

"generate": "dotenv -e ../../.env -- prisma generate && prisma format",

And then:

npm run --workspace @mypkg/prisma-client db:seed:dev

@janpio janpio added the topic: turborepo https://turborepo.org/ label Apr 19, 2022
@zomars
Copy link
Author

zomars commented Aug 1, 2022

Why can't this work out of the box?

Also the docs are kinda misleading:

The Prisma CLI looks for .env files, in order, in the following locations:

In the root folder of your project (./.env)

In a monorepo, the root of the project is the monorepo root. It makes sense to traverse up until the root of the monorepo.

@leerob
Copy link

leerob commented Aug 1, 2022

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

@zomars
Copy link
Author

zomars commented 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?

@zomars
Copy link
Author

zomars commented Oct 17, 2023

This would also help with #1255 and #9726

@senghuotlay
Copy link

Any update on this guys?

@kosgo
Copy link

kosgo commented May 7, 2024

up, having the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: .env topic: monorepo topic: turborepo https://turborepo.org/
Projects
None yet
Development

No branches or pull requests

7 participants