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.

(Re)Introspection does not respect variables in dotenv file when schema is located in a custom directory

See original GitHub issue

Bug description

When the schema file is located in a custom directory, the dotenv file located in the same directory as the schema file, is not read by the Prisma CLI.

How to reproduce

Assuming we have the following project structure,

  • test-prisma-dotenv
    • db
      • .env
      • schema.prisma
    • node_modules
    • package.json
    • yarn.lock

Then run the following command to re-introspect in the project root directory

yarn prisma introspect --schema db/schema.prisma --experimental-reintrospection

Results in such error

Introspecting based on datasource defined in db/schema.prisma …
Error: Error in datamodel: ErrorCollection { errors: [EnvironmentFunctionalEvaluationError { var_name: "DATABASE_URL", span: Span { start: 160, end: 179 } }] }

However, if we run the command without the --experimental-reintrospection, it works as expected that the Prisma CLI respects the environment variable in the dotenv file.

Expected behavior

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

generator client {
  provider = "prisma-client-js"
}

Environment & setup

  • OS:
  • Database:
  • Prisma version:
  • Node.js version:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Sep 29, 2020

Please create a new issue @mjknight50 and supply some more information - best fill the issue template.

1reaction
mjknight50commented, Sep 29, 2020

@timsuchanek This same error happened for me today. ErrorCollection { errors: [EnvironmentFunctionalEvaluationError { var_name: "DATABASE_URL"

@prisma/cli”: “^2.8.0”, “@prisma/client”: “^2.6.2”,

My schema is:

generator client {
  provider = "prisma-client-js"
}

datasource mysql {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

The path is irregular: /server/data/prisma/schema.prisma

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing .env files and setting variables - Prisma
Learn how to manage .env files and set environment variables.
Read more >
dotenv file is not loading environment variables - Stack Overflow
in my case i am compiling ts in dist folder and env files are not located in dist folder, but in the root...
Read more >
Building a schema | Full-Stack Quickstart - Apollo GraphQL
Your GraphQL schema defines what types of data a client can read and write to your graph. Schemas are strongly typed, which unlocks...
Read more >
Environment variables | dbt Developer Hub
Use environment variables to customize the behavior of your dbt project. ... Environment variables keys are uppercased and case sensitive.
Read more >
Configuration Options | Directus Docs
Environment variables are used for all configuration within a Directus ... If the config path has no file extension, or a file extension ......
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