railwayapp / nixpacks

App source + Nix packages + Docker = Image
https://nixpacks.com
MIT License
2.36k stars 226 forks source link

Unable to get prisma 5 with nixpacks openssl #1030

Open Maxim-Filimonov opened 7 months ago

Maxim-Filimonov commented 7 months ago

Is there an existing issue for this?

Describe the bug

Following up on the issue Prisma does support open ssl 3.0.x now. However, for some reason I'm still not able to use nixpack with Prisma. I tried installing libssl-dev in setup stage and got the same error.

To reproduce

After building i get the following error on trying to instantiate PrismaClient(): index.ts

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

Error:

PrismaClientInitializationError: Unable to require(`/app/node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node`).

Prisma cannot find the required `libssl` system library in your system. Please install openssl-3.0.x and try again.

Details: libssl.so.3: cannot open shared object file: No such file or directory

at new e (/app/node_modules/@prisma/client/runtime/library.js:26:1871)

Noticed that it's using libquery_engine-debian-openssl-3.0.x.so.node - shouldn't be using ubuntu version not debian ?

Expected behavior

Able to build and deploy application using Prisma.

Environment

nixpacks.toml

[phases.setup]
aptPkgs = ["..."]
[phases.build]
cmds = ["...", "bunx prisma generate", "bunx prisma migrate deploy"]

package.json

 "dependencies": {
    "@prisma/client": "5.7.0",
  },

Bun: 1.0.17

I have no problems running locally.

github-actions[bot] commented 7 months ago

Hello, @Maxim-Filimonov! Thanks for your submission.

Our team will respond soon. If you need more immediate help, try our Forum or our Discord. Thanks!

coffee-cup commented 7 months ago

We have an example that builds and runs no problem using Prisma 5 and bun https://github.com/railwayapp/nixpacks/tree/main/examples/node-bun-prisma.

I can check this out further, but there is evidence of both working so I am not sure what is going on with your specific repo. Do you have a sample repo that doesn't work with Bun?

Maxim-Filimonov commented 7 months ago

@coffee-cup I tried using linked example and it fails with different error for some reason.


$ bunx prisma migrate deploy

Prisma schema loaded from prisma/schema.prisma

Datasource "db": PostgreSQL database "railway", schema "public" at "roundhouse.proxy.rlwy.net:17360"

Error: P1001: Can't reach database server at `roundhouse.proxy.rlwy.net`:`17360`

Please make sure your database server is running at `roundhouse.proxy.rlwy.net`:`17360`.

error: script "start" exited with code 1 (SIGHUP)

$ bunx prisma migrate deploy

I did add shared variable DATABASE_URL. Project on railway -> https://railway.app/project/f43b6f45-bce0-4138-bb1f-4dedca53ed97 Tried recreating postgres service - no luck.

Also tried using PRIVATE_DATABASE_URL from pg got this instead:

Error: P1001: Can't reach database server at `postgres.railway.internal`:`5432`

Please make sure your database server is running at `postgres.railway.internal`:`5432`.
thomas779 commented 7 months ago

Bumping this as I'm getting the exact issue to @Maxim-Filimonov. Everything works locally, but deploying to railway is a journey of painful debugging.

@coffee-cup if you need some hard evidence, I would suggest running through these steps:

  1. fork this repo: https://github.com/amorriscode/elysia-starter
  2. "prisma": "5.7.1" and "@prisma/client": "5.7.1" (versions shouldn't matter, but some devs reported having it fixed downgrading or upgrading... error was replicated with v5.3.x and v5.7.x on my side).
  3. cp this schema.prisma:

What's your Prisma schema set-up Maxim ? This is mine:

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

generator client {
    provider      = "prisma-client-js"
    output        = "./generated/client"
    binaryTargets = ["native", "linux-musl", "debian-openssl-3.0.x"]
}

nixpacks.toml:

[phases.setup]
nixPkgs = ['bun']

[phases.install]
cmds = ['bun install']

[phases.build]
cmds = ['bunx prisma generate', 
        'bunx prisma migrate deploy', 
        'bun build --target=bun ./src/index.ts --outdir ./build']

[start]
cmd = 'bun run src/index.ts'

Error:

PrismaClientInitializationError: Unable to require(`/app/prisma/generated/client/libquery_engine-debian-openssl-3.0.x.so.node`).
Prisma cannot find the required `libssl` system library in your system. Please install openssl-3.0.x and try again.
Details: libssl.so.3: cannot open shared object file: No such file or directory

Tried to add 'openssl_3_0_x to my nixPkgs = ['bun', 'openssl_3_0_x'] but that didn't work.

Also, changing start cmd from bun run src/index.ts to bun run build/indexjs will produce error:

Server is running at localhost:5000
1 | __dirname
^
ReferenceError: Can't find variable: __dirname
at /app/build/index.js:1604:69
at processTicksAndRejections (:61:76)
imadbz commented 6 months ago

+1 couldn't get it to work either

baptisteArno commented 5 months ago

I have the exact same error when trying to deploy an Elysia app. Has anyone found a fix?

Maxim-Filimonov commented 5 months ago

My fix was to migrate to fly.io :|

iloveitaly commented 5 months ago

--libs openssl will fix the issue, or we can get this PR merged :)

https://github.com/railwayapp/nixpacks/pull/1054

Maxim-Filimonov commented 5 months ago

@iloveitaly where to add --libs openssl ?

baptisteArno commented 5 months ago

@iloveitaly Nah, I that's not it... I think nixpacks even detected that it needs openssl by default for my project.

Still, I tried to specifically tell it to add the openssl lib with the env NIXPACKS_PKGS=openssl

╔═══════════════ Nixpacks v1.20.0 ══════════════╗
║ setup │ openssl, nodejs_18, bun, openssl ║
║───────────────────────────────────────────────║
║ install │ bun install ║
║───────────────────────────────────────────────║
║ build │ bun build:chat-api ║
║───────────────────────────────────────────────║
║ start │ bun start:chat-api ║
╚═══════════════════════════════════════════════╝

The problem happens at runtime, on the docker when the app is running, on Prisma init, it says:

PrismaClientInitializationError: Unable to require(`/app/node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node`).

Prisma cannot find the required `libssl` system library in your system. Please install openssl-3.0.x and try again.

Details: libssl.so.3: cannot open shared object file: No such file or directory

at new e (/app/node_modules/@prisma/client/runtime/library.js:26:1871)
iloveitaly commented 5 months ago

You need it as a lib, not as a package. Without this the ENV config is not changed. Take a look at the linked PR: https://github.com/railwayapp/nixpacks/pull/1054

GautierT commented 4 months ago

Hey ! I did not quite understand the latest message. What is the solution to avoid this error : Unable to require(/app/node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node). 2024-03-13T14:39:50.020131817Z Prisma cannot find the requiredlibsslsystem library in your system. Please install openssl-3.0.x and try again.

Thanks !

ksaitor commented 3 months ago

Even on the latest prisma@^5.11.0 still getting this error on Nixpacks (running inside Coolify)

╔═════════════ Nixpacks v1.21.2 ═════════════╗
║ setup │ nodejs_21, bun, openssl ║
║────────────────────────────────────────────║
║ install │ bun i --no-save ║
║────────────────────────────────────────────║
║ build │ echo Skip build process ║
║────────────────────────────────────────────║
║ start │ bun run worker/main.worker.ts ║
╚════════════════════════════════════════════╝
PrismaClientInitializationError: Unable to require(`/app/node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node`).
Prisma cannot find the required `libssl` system library in your system. Please install openssl-3.0.x and try again.
ksaitor commented 3 months ago

--libs openssl

where do you add --libs openssl ? @iloveitaly

@Maxim-Filimonov were you able to resolve this?

Maxim-Filimonov commented 3 months ago

@ksaitor I haven't tried since it wasn't working when I needed it for initial launch. It works pretty well on fly I don't really see a reason why try to move it back to railway TBH.

JakeCooper commented 3 months ago

Fixable by simply specifying binaryTargets

https://github.com/amorriscode/elysia-starter/issues/2#issuecomment-2019438468

ksaitor commented 3 months ago

added NIXPACKS_LIBS=openssl and it worked! notice: not NIXPACKS_PKGS

cc @baptisteArno check it out

JakeCooper commented 3 months ago

@ksaitor Could you link the Railway project where it works or a repo with it working so that we can fix it at the nixpacks level?

ksaitor commented 3 months ago

@ksaitor Could you link the Railway project where it works or a repo with it working so that we can fix it at the nixpacks level?

@JakeCooper I'm not on Railway. I'm on Coolify, that's using Nixpacks under the hood. Nixpacks v1.21.2.

nicnocquee commented 1 month ago

@ksaitor where in coolify did you add NIXPACKS_LIBS=openssl? I try to do prisma migration before the build but it cannot reach the database no matter what.

ksaitor commented 1 month ago

@ksaitor where in coolify did you add NIXPACKS_LIBS=openssl? I try to do prisma migration before the build but it cannot reach the database no matter what.

Go to your project > Configuration > Environment Variables

And, perhaps try checking "Build Variable".

I'm not running prisma migrations during build in my app. So i can't comment more here unfortunately.

Screenshot 2024-06-16 at 14 00 02