Prisma not reading .env values in turbo repo
Answered
useless posted this in #help-forum
uselessOP
I have a turborepo with prisma as a package. In the
error message
my folder structure is as follows
schema.prisma
.env
turbo.json
schema.prisma
DATABASE_URL
is not being read or accessed.error message
> database@0.0.1 db:migrate
> prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Environment variable not found: DATABASE_URL.
--> prisma\schema.prisma:14
|
13 | provider = "postgresql"
14 | url = env("DATABASE_URL")
|
Validation Error Count: 1
[Context: getConfig]
Prisma CLI Version : 5.17.0
Tasks: 0 successful, 1 total
Cached: 0 cached, 1 total
Time: 2.472s
Failed: database#db:migrate
ERROR run failed: command exited (1)
ELIFECYCLE Command failed with exit code 1.
my folder structure is as follows
.env
turbo.json
/packages
/database
/prisma
/schema.prisma
schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
.env
DATABASE_URL=""
turbo.json
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": [".env"],
"globalEnv": ["DATABASE_URL"],
"tasks": {
"clean": {
"cache": false
},
"db:gen": {},
"db:migrate": {
"dependsOn": ["^db:migrate"],
"env": ["DATABASE_URL"]
},
"db:studio": {
"env": ["DATABASE_URL"],
"outputs": []
},
"db:format": {},
"build": {
"dependsOn": ["^db:gen", "^build"],
"inputs": ["$TURBO_DEFAULT", ".env*"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {
"dependsOn": ["^lint"]
},
"dev": {
"persistent": true,
"env": [
"DATABASE_URL",
"NODE_ENV",
"ALLOWED_ORIGINS",
"IPINFO_API_KEY",
"JWT_TOKEN_REFRESH_SECRET",
"JWT_TOKEN_ACCESS_SECRET",
"REFRESH_TOKEN_EXPIRATION"
]
}
}
}
4 Replies
uselessOP
Found a solution using
dot-env
cli toolAnswer
weird ik but can't do much else if you don't want to manually load the file with dotenv
uselessOP
tried it but didn't work for me, I saw it recommended in the Prisma package of turborepo examples.
maybe because I am on windows?
maybe because I am on windows?