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!
Problem solved.
I didn't have to surround the URL with " in my .env..