Reputation: 591
I am trying to deploy my NestJS application with prisma in production. But when launching my server, I have this error:
nestjs | PrismaClientInitializationError: error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.
nestjs | --> schema.prisma:11
nestjs | |
nestjs | 10 | provider = "postgresql"
nestjs | 11 | url = env("DATABASE_URL")
nestjs | |
nestjs |
nestjs | Validation Error Count: 1
nestjs | at Object.loadEngine (/app/node_modules/@prisma/client/runtime/index.js:35591:19)
nestjs | at async Object.instantiateLibrary (/app/node_modules/@prisma/client/runtime/index.js:35520:5)
nestjs | at async Object.start (/app/node_modules/@prisma/client/runtime/index.js:35670:5)
nestjs | at async Proxy.onModuleInit (/app/dist/prisma.service.js:14:9)
nestjs | at async Promise.all (index 0)
nestjs | at async callModuleInitHook (/app/node_modules/@nestjs/core/hooks/on-module-init.hook.js:43:5)
nestjs | at async NestApplication.callInitHook (/app/node_modules/@nestjs/core/nest-application-context.js:178:13)
nestjs | at async NestApplication.init (/app/node_modules/@nestjs/core/nest-application.js:96:9)
nestjs | at async NestApplication.listen (/app/node_modules/@nestjs/core/nest-application.js:155:33)
nestjs | at async bootstrap (/app/dist/main.js:8:5) {
nestjs | clientVersion: '3.11.1',
nestjs | errorCode: 'P1012'
nestjs | }
My docker-compose.yml :
version: "3.2"
services:
nestjs:
container_name: nestjs
build:
context: ./apps/nestjs
dockerfile: Dockerfile.prod
env_file:
- ./apps/nestjs/.env
My .env :
DATABASE_URL="postgres://myUser:myPassword@myHost:myPort/myDB?sslmode=require"
What I tried to do :
.env
was taken into account. When I go into the container, my environment variable existspostgres
to postgresql
Any ideas?
Thanks you!
Upvotes: 19
Views: 23731
Reputation: 21
my solution : make new env variable name like DB or DBLINK (capitalcase) then use it
Upvotes: 2
Reputation: 41
you could use npm uninstall prisma
then npm install prisma
and finally npx prisma generate
.
That worked for me. It will create a new prisma client based on your prisma schema file.
Upvotes: 4
Reputation: 105
In ts file replace:
import { PrismaClient } from "@prisma/client/edge";
with
import { PrismaClient } from "@prisma/client";
Upvotes: -1
Reputation: 531
I had the same problem,
Upvotes: 1
Reputation: 477
Make sure that your env variables are defined in .env and not just .env.local
Upvotes: -1
Reputation: 9
For me the problem was a mismatch between versions of Prisma CLI and Prisma Client.
Updating both to the same version solved the problem
Upvotes: -1
Reputation: 5133
You didn't have to put " around your URL but you may need it and it should have worked.
In fact, it is an issue on old docker-compose version. Upgrade it and welcome " back !
Upvotes: 0
Reputation: 591
Problem solved.
I didn't have to surround the URL with " in my .env..
Upvotes: 28