Environnement variable not found in pre-deployment step
uptoo-owner
TRIALOP

a year ago

Hello!
I have a backend server (NestJS) in a Turborepo that I want to deploy.
I'm using PrismaORM for my database, and to properly apply my data model, I use the command:
turbo db:deploy --filter=api => /apps/api > pnpm run db:deploy => pnpx prisma migrate deploy

The problem is that Prisma can't find my environment variable:
error: Environment variable not found: DATABASE_URL.

Even though it is correctly set in the "Variables" tab.

Has anyone encountered similar issues?

Solved

5 Replies

a year ago

Hello,

Perhaps you have not saved (deployed) the changes after adding the variables?

Though looks like nothing has currently crashed!

Best,

Brody


Status changed to Awaiting User Response Railway about 1 year ago


brody

Hello,Perhaps you have not saved (deployed) the changes after adding the variables?Though looks like nothing has currently crashed!Best,Brody

uptoo-owner
TRIALOP

a year ago

Hi,

Unfortunately, the environments were properly saved.

I ended up disabling the deploy step — I prefer handling it manually until everything works correctly.

However, I'm facing another issue with environment variables on a Next.js app.

Deployment ID:0fd54534-fd41-483d-aef6-30ea0873ea20

The OPENAI_API_KEY is correctly set in the Deployment Details tab as ${{shared.OPENAI_API_KEY}}.

Yet, as seen in the deploy logs, my application fails to access the variable:

Error: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }). at new lg (.next/server/app/api/assistant/route.js:13:25518)

The strange part is that another environment variable prefixed with NEXT_PUBLIC_ works fine.

I’m aware that Next.js disables non-NEXT_PUBLIC_ environment variables on the client side, but in this case, I’m on the server side (route.js).

Has anyone encountered a similar issue?


Status changed to Awaiting Railway Response Railway about 1 year ago


a year ago

Hello,

Everything on our side is working correctly -


Perhaps it would help if you ran your turbo app in lose mode? -

https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#environment-modes

Best,
Brody


Status changed to Awaiting User Response Railway about 1 year ago


uptoo-owner
TRIALOP

a year ago

Man, you saved me!!! raised_hands emoji That was exactly the issue — switching to loose mode fixed everything.

I really appreciate your help, thanks a ton!


Status changed to Awaiting Railway Response Railway about 1 year ago


a year ago

Happy to help!


Status changed to Awaiting User Response Railway about 1 year ago


Status changed to Solved brody about 1 year ago


Loading...