question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment variable not found

See original GitHub issue

Bug description

Since version 2.24.0 I got next error while making requests to my graphql server

"Error: Context creation failed: ",
"Invalid `prisma.user.findUnique()` invocation:",
"  error: Environment variable not found: DATABASE_URL.",
"  -->  schema.prisma:3",
"   | ",
" 2 |   provider = \"postgresql\"",
" 3 |   url      = env(\"DATABASE_URL\")",
"   | ",

Commands like prisma migrate works correctly

I have next file structure

├── prisma
│   └── schema.prisma
├── src
│   └── server.ts
├── .env

In version 2.23.0 everything works as expected

How to reproduce

  1. Create graphql-server with apollo-server and prisma
  2. Add PrismaClient to context
  3. Make graphql request

Expected behavior

No response

Prisma information

My schema.prisma file starts like this

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["orderByRelation", "selectRelationCount"]
}

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js: 14.15.4
  • apollo-server-express: 2.25.1

Prisma Version

2.24.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
oceandramacommented, Jun 14, 2021

@janpio Yes, I use Yarn Workspaces in my project

4reactions
ljosberinncommented, Jun 12, 2021

I’m seeing the same issue beginning with version 2.24.0. In my case, it’s due to different behaviour leading up to /sdk/utils/tryLoadEnvs.

v2.23.0:

image image config value being passed to getPrismaClient: image

Notice the schemaEnvPath being 'C:\\Users\\gerr.it\\Desktop\\dev\\keystone-heroes\\packages\\@keystone-heroes\\db\\.env' and debug statements being present.

v2.24.0

image image config value being passed to getPrismaClient: image

Notice the line difference which in the code screenshot indicating the changes between the versions, although this function wasnt touched and how schemaEnvPath now is 'C:\\Users\\gerr.it\\Desktop\\dev\\keystone-heroes\\node_modules\\.prisma\\client\\packages\\@keystone-heroes\\db\\.env'.

It’s late right now, I’ll try to whip up a repro tomorrow.

Edit: updated the config values. Apparently despite the name, config.relativeEnvPaths are no longer relative in 2.24.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with Environment Variables
Environment variable is not set. If the error message states that the environment variable is not set, IT MEANS PRECISELY THAT ! The...
Read more >
Environment variables not found symfony - Stack Overflow
I've run into this problem myself. You have to explicitly map the environment variables you want to make accessible to php/symfony in ...
Read more >
Environment variable not found since symfony 5.1 #126 - GitHub
Hello Since symfony 5.1 when running vendor / bin / behat there is an error message In EnvVarProcessor.php line 171: Environment variable not...
Read more >
New Environment Variables Not Working in Windows 10
I am trying to put in paths to my php install and php composer. Here's what I got: C:\xampp\php\;. C:\xampp\htdocs\bill-dev-site\;.
Read more >
Environment Variables > Symfony 6 Fundamentals
If you're not familiar with environment variables, they're variables that you can set on any system (Windows, Linux, whatever.)... and then you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found