1

My prisma isn't able to find .env file even though that file is create by npx prisma init.

Folder Structure:

--prisma
  -- schema.prisma
--.env
--script.ts

Schema code:

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

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

model User {
  id   Int    @id @default(autoincrement())
  name String
}

.env:

DATABASE_URL="postgres://xxxxxx:[email protected]/test"

script.ts:

import { PrismaClient } from '@prisma/client/edge'
const prisma = new PrismaClient()


const main = async () => {
    const user = await prisma.user.create({data:{name:"Sai"}})
    console.log(user)
} 

main()
    .catch((err) => console.log(err))
    .finally(async () => {
        await prisma.$disconnect()
    })

Error prisma show while running the script.ts file:

PrismaClientInitializationError: 
Invalid `prisma.user.create()` invocation:


error: Environment variable not found: DATABASE_URL.

I tried running, npx prisma migrate -dev --name init and also npx prisma generate

Still showing the same error.

0

2 Answers 2

1

I am facing the exact same issue on my Ubuntu20 server, So I directly added the env variable to server environment. with given command.

export DATABASE_URL=postgresql://test:test@localhost:5432/test

This really fixed my issue.

You can check the reference

Sign up to request clarification or add additional context in comments.

Comments

0

instead of using @prisma/client/edge use @prisma/client
import { PrismaClient } from '@prisma/client'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.