P
Prisma19h ago
gkh

With PrismaORM 6.6 "DATABASE_URL" Cannot Be Found

I'm using SvelteKit. I've updated the schema to use the new ESM client build, but unless I directly export DATABASE_URL prior to running the image or even the local build, it runs into errors:
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:9
|
8 | provider = "mysql"
9 | url = env("DATABASE_URL")
|
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:9
|
8 | provider = "mysql"
9 | url = env("DATABASE_URL")
|
generator client {
provider = "prisma-client"
output = "../generated/prisma"
moduleFormat = "esm"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client"
output = "../generated/prisma"
moduleFormat = "esm"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
I've tried everything can can't figure out what I am missing.
1 Reply
Prisma AI Help
Prisma AI Help19h ago
You chose to compile with the bot. One moment while I piece together your answer… Based on the knowledge sources, this is a common issue with Prisma not being able to find the DATABASE_URL environment variable. Here are some possible solutions: 1. Check your .env file location: Make sure your .env file is in the correct location. Prisma looks for the .env file in specific places, and if it's not there, it won't find your DATABASE_URL variable. The .env file should typically be in the root of your project or in the same directory as your schema.prisma file DATABASE_URL not found in Amplify. 2. Verify .env file format: Ensure your DATABASE_URL is properly formatted in your .env file without quotes:
DATABASE_URL=mysql://USER:PASSWORD@HOST:PORT/DATABASE

DATABASE_URL=mysql://USER:PASSWORD@HOST:PORT/DATABASE


3. Check for special characters: If your password contains special characters like '$', you might need to escape them. For example, replace '$' with '%24' Invalid Environment Variable DATABASE_URL. 4. Multiple .env files: Check if you have multiple .env files in your project. The one closest to the root might take precedence prisma db pull doesn't read .env file. 5. Temporary workaround: You can manually set the environment variable in your code before initializing Prisma:
process.env.DATABASE_URL = "mysql://user:password@host:port/database";

process.env.DATABASE_URL = "mysql://user:password@host:port/database";

6. Direct datasource URL: As a last resort, you could directly specify the URL in your schema.prisma file instead of using env(), but this is not recommended for production as it exposes your credentials. If none of these solutions work, you might want to check if there are any specific issues with the version of Prisma you're using, as there have been regressions in the past where environment variables weren't properly read 4.10.0 unexpected error. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.

Did you find this page helpful?