How to use env vars in a Monorepo

It seems that I can't hand down my env variables via Turborepo if I try to do that I get into the "select project" menu
15 Replies
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
For example I do need them to hand down in my Vercel Deployment but since vercel can't hand them down themselves I would love to see that Convex supports Turborepo Envs https://github.com/The-Creative-Programming-Group/Weather-App/actions/runs/7748221030/job/21130424349 Example GH Action where the env cannot be handed trough
Indy
Indyβ€’13mo ago
I think this setup is missing a deploy key thus you're being asked to auth with a browser. See the step 4 in vercel setup here: https://docs.convex.dev/production/hosting/vercel @Michal Srb who wrote many of these docs.
Using Convex with Vercel | Convex Developer Hub
Host your frontend on Vercel and your backend on Convex.
Indy
Indyβ€’13mo ago
Also we are working on setting environment variables from the CLI so that should become scriptable in the not too distant future.
ian
ianβ€’13mo ago
I’ll be publishing a template with nextjs and turborepo in the next day or so which passes env vars during local development via dotenv loaded in the next config, if that helps
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
I think that would be so helpful. Thank you β™₯️
ian
ianβ€’13mo ago
@FleetAdmiralJakob πŸ—• πŸ—— πŸ—™ I've published a template for monorepos. Honestly I found that none of the env vars were really shared, since next needs the NEXT_PUBLIC prefix, Expo needs EXPO_PUBLIC, and convex backend env vars are stored in the dashboard. The template is now live: https://www.convex.dev/templates/monorepo
Templates
The backend application platform with everything you need to build your product.
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
Could you add the correct .env.example files so it is obvious where and which envs should be added? But thank you very much for it. I think it is very useful and helps the whole Convex ecosystem.
ian
ianβ€’13mo ago
there's .example.env in each of the apps/ directories already @FleetAdmiralJakob πŸ—• πŸ—— πŸ—™ - what would you want to be different? running npx convex commands in packages/db will set the right values too
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
My problem basically is that I can only set enviroment variables in the top dir in CI and need to run all the convex scripts in CI. @ian If you understand what I mean πŸ˜‚ Maybe I'm just a little bit confused
ian
ianβ€’13mo ago
gotcha. why can CI only set env there? one thing that could work is adding symlinks to the same shared .env in the root
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
I set envs in GH Actions and I guess that's a limitation
ian
ianβ€’13mo ago
are you setting environment variables via .env file or just set in the execution environment?
FleetAdmiralJakob πŸ—• πŸ—— πŸ—™
I'm setting them in CI via this: (Sorry for the mobile view)
No description
ian
ianβ€’13mo ago
yeah that doesn't write to .env but sets them globally so I imagine they'd all work as-is process.env.BLAH reads things like
export BLAH="hi";
some_bash_command
export BLAH="hi";
some_bash_command
Michal Srb
Michal Srbβ€’13mo ago
Environment variables can now be set via the CLI: https://news.convex.dev/announcing-convex-1-10/
Convex News
Announcing Convex 1.10
Convex keeps getting better. This time we’re focused on helping you debug your apps and we’re also gearing up for the open-source release of the Convex backend. Highlights: * Request IDs let you find related logs * Improved error messages and new warnings * New CLI commands: convex export, convex env,

Did you find this page helpful?