Deploying Monorepo with Next-Forge
pedroota
HOBBYOP

10 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

10 months ago

6452898b-4334-4a3f-b118-d8bfb71e8f8c


10 months ago

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


pedroota
HOBBYOP

10 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


10 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

10 months ago

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


10 months ago

Oh, now I got it.


pedroota
HOBBYOP

10 months ago

Yes, that's the problem


10 months ago

Are you using dotenv?


pedroota
HOBBYOP

10 months ago

hmm, nope


pedroota
HOBBYOP

10 months ago

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


10 months ago

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


pedroota
HOBBYOP

10 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


10 months ago

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


pedroota
HOBBYOP

10 months ago

Of course!

1398105580471844995


10 months ago

use process.env.DATABASE_URL


10 months ago

that's the issue


pedroota
HOBBYOP

10 months ago

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

1398106326709571796


10 months ago

cool! did it work?


pedroota
HOBBYOP

10 months ago

Not yet!

1398106689252888679


pedroota
HOBBYOP

10 months ago

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


10 months ago

no!


10 months ago

but I see other issue


10 months ago

"no config path provided"


10 months ago

oh nvm it looks for the root one either way


pedroota
HOBBYOP

10 months ago

yes!


10 months ago

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


pedroota
HOBBYOP

10 months ago

yes! it's in local environment


pedroota
HOBBYOP

10 months ago

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


10 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.


10 months ago

locally it would work fine


pedroota
HOBBYOP

10 months ago

Yes! I'd love an example


pedroota
HOBBYOP

10 months ago

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


pedroota
HOBBYOP

10 months ago

but ill try


10 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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...