Search code examples
next.jsprismavercel

env variable is not set during build on Vercel


While deploying a monorepo app with turbo build on vercel, there are erros about accessing the env vars. On local It can access the env var in .env.local, however on vercel platform it suddenly stopped working and started complaining about it.

all env variables are set in the dashboard enter image description here

but during build it it fails to access the env variables. enter image description here

Why it can't access whose env vars?


Solution

  • If you are using prisma in a Turborepo and trying to deploy to Vercel and you are seeing the error: Environment Variable not found: DATABASE_URL, you need to add DATABASE_URL to the turbo.json environment variables

    If you want tasks to remain cached,

    "globalPassThroughEnv": ["DATABASE_URL"],
    

    or if you want tasks to miss cache when var is updated

    "globalEnv": ["DATABASE_URL"],
    

    or maybe you only want it available during build

    "tasks": {
      "build": {
        "env": ["DATABASE_URL"]
      }
    }