Deploying Monorepo with Next-Forge
pedroota
HOBBYOP

8 months ago

I am deploying a shared monorepo on Railway with the next-forge template (https://www.next-forge.com)

The problem I am facing is, there's a package called database (I'm using Drizzle) and for me to run the migrations this package needs a .env inside. As it's not an deployable app, I can't put .envs on it inside Railway.

How to proceed on that situation?

$10 Bounty

34 Replies

pedroota
HOBBYOP

8 months ago

6452898b-4334-4a3f-b118-d8bfb71e8f8c


8 months ago

Hi! Did you try the "Shared Monorepos" guide?


pedroota
HOBBYOP

8 months ago

Yes! I used it to deploy the backend and the frontend, but the database package needs a .env inside to run the migrations. I don't really know how to proceed on that inside Railway


8 months ago

And may I ask why don't you have a .env with the needed vars in that package? That's how turborepo works, all my packages have their own env file


pedroota
HOBBYOP

8 months ago

I do have! But I need to add the envs inside the package on Railway too


8 months ago

Oh, now I got it.


pedroota
HOBBYOP

8 months ago

Yes, that's the problem


8 months ago

Are you using dotenv?


pedroota
HOBBYOP

8 months ago

hmm, nope


pedroota
HOBBYOP

8 months ago

I am using a package called @t3-oss/env-nextjs


8 months ago

and did you set the runtimeEnv property in the env.mjs file?


pedroota
HOBBYOP

8 months ago

I did! The problem is: I need to create a ".env" for the database package inside railway. In my local environment it works perfectly because inside the database package I have the .env file, but i need it inside railway as well for it to work and run the migrations


8 months ago

can you show me your drizzle.config.ts? you can hide any sensitive info there


pedroota
HOBBYOP

8 months ago

Of course!

1398105580471845000


8 months ago

use process.env.DATABASE_URL


8 months ago

that's the issue


pedroota
HOBBYOP

8 months ago

I did this to validate the env as well as soon as keys() is not being used anymore

1398106326709571800


8 months ago

cool! did it work?


pedroota
HOBBYOP

8 months ago

Not yet!

1398106689252888600


pedroota
HOBBYOP

8 months ago

Do I need to keep the .env inside /database package?


8 months ago

no!


8 months ago

but I see other issue


8 months ago

"no config path provided"


8 months ago

oh nvm it looks for the root one either way


pedroota
HOBBYOP

8 months ago

yes!


8 months ago

This is local, right? could u try in a staging env on railway?


pedroota
HOBBYOP

8 months ago

yes! it's in local environment


pedroota
HOBBYOP

8 months ago

i don't see how it's going to help running on staging env on railway, could you elaborate on that?


8 months ago

I had a project (not a monorepo) that used dotenv to setup env vars, upon deploying on railway it would conflict and would not use the Railway injected env vars.


8 months ago

locally it would work fine


pedroota
HOBBYOP

8 months ago

Yes! I'd love an example


pedroota
HOBBYOP

8 months ago

hmm, i dont think it's related to that tbh


pedroota
HOBBYOP

8 months ago

but ill try


8 months ago

In the end I solved it by removing dotenv and upgrading to bun and using Bun.env.
I wonder if nextjs-env is doing something similar with your project


Loading...