prisma: `bunx prisma generate` breaking

Bug description

https://bun.sh/guides/ecosystem/prisma

This guide includes that node is required because of Prisma’s dependency on the node API (at least from what the Devs at Bun have told me)

How to reproduce

Have bun installed curl -fsSL https://bun.sh/install | bash in linux environment with node not installed at all

Follow the guide and when you run bunx prisma generate there aren’t any message nor error message being sent and it gets stuck (because it relies on node API)

Expected behavior

bunx prisma generate should work exactly like npx prisma generate

Prisma information

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

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

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

model Flights {
    id String @id 
    pilotID String @database.VarChar(255)
    flightMessageID String @database.VarChar(255)
    pilotMessageID String @database.VarChar(255)
    modMessageID String @database.VarChar(255)
    serverLink String @database.VarChar(255)
    moderatorID String @database.VarChar(255)
    flightDeparted String @database.VarChar(255)
    date String @database.VarChar(255)
    year String @database.VarChar(255)
    month String @database.VarChar(255)
    flightNumber String @database.VarChar(255)
}

model FlightCheck {
    id  String @id
    flightGoingOn String @database.VarChar(255)
    duration String @database.VarChar(255)
    timeZone String @database.VarChar(255)
    date String @database.VarChar(255)
    year String @database.VarChar(255)
    month String @database.VarChar(255)
}

model PassengerDetails {
    id String @id @unique
    timeZone String @database.VarChar(255)
    skyMiles String @database.VarChar(255)
    balance String @database.VarChar(255)
    badges String @database.VarChar(255)

    rollDuration String @database.VarChar(255)
    rollDate String @database.VarChar(255)
    rollYear String @database.VarChar(255)
    rollMonth String @database.VarChar(255)
    rollTimeZone String @database.VarChar(255)

    crimeDuration String @database.VarChar(255)
    crimeDate String @database.VarChar(255)
    crimeYear String @database.VarChar(255)
    crimeMonth String @database.VarChar(255)
    crimeTimeZone String @database.VarChar(255)

    betDuration String @database.VarChar(255)
    betDate String @database.VarChar(255)
    betYear String @database.VarChar(255)
    betMonth String @database.VarChar(255)

    workDuration String @database.VarChar(255)
    workDate String @database.VarChar(255)
    workYear String @database.VarChar(255)
    workMonth String @database.VarChar(255)
}

model PilotFlights {
    id String @id @unique
    duration String @database.VarChar(255)
    timeZone String @database.VarChar(255)
    flightReviewMessageID String @database.VarChar(255)
    flightReviewed String @database.VarChar(255)
    warning String @database.VarChar(255)
    date String @database.VarChar(255)
    year String @database.VarChar(255)
    month String @database.VarChar(255)
}

declare module "discord.js" {
    export interface Client {
        commands: Collection<string, any>
        database: PrismaClient
    }
};

client.database = new PrismaClient();
    await client.database.$connect().catch(async (error) => {
        console.error(`[WARNING] ${error} whilst connecting to database`);
    })

const flightCheckQuery = await interaction.client.database.flightCheck.findUnique({ where: { id: "flight" } });

Environment & setup

  • OS: Linux (pyterodactyl with bun image)
  • Database: MySQL however it should be for every database that uses Prisma
  • Bun version: 1.0.3

Prisma Version

bunx prisma -v doesn't work

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 8
  • Comments: 19

Most upvoted comments

Appears to be fixed in Bun 1.0.30

Hey just as a heads up the norm here is to react to the OP’s message with 👍🏻 rather then replying “Same Issue” and pinging everyone following said issue for updates.

Also, this isn’t even a prisma issue. It’s a bun issue given it’s supposed to be a drop-in replacement for NodeJS.

My comment above only covered the surface level issues that bun has with this package. After I forcibly resolved that issue locally it revealed a whole bunch of other issues for things that bun just doesn’t support yet that prisma relies upon.

EDIT: Opened a issue on buns repo https://github.com/oven-sh/bun/issues/8113

So I ended up pulling their repo down to dig into it a bit and it seems the following code is evaluating incorrectly on bun in certain scenarios.

https://github.com/prisma/prisma/blob/0400b2a659a378e322753ecbcf74850614925859/packages/cli/src/bin.ts#L180-L197

With PNPM

$ pnpm exec prisma --help
require.main === module true
Remaining Output
◭  Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.io)

Usage

  $ prisma [command]

Commands

            init   Set up Prisma for your app
        generate   Generate artifacts (e.g. Prisma Client)
              db   Manage your database schema and lifecycle
         migrate   Migrate your database
          studio   Browse your data with Prisma Studio
        validate   Validate your Prisma schema
          format   Format your Prisma schema
         version   Displays Prisma version info
           debug   Displays Prisma debug info

Flags

     --preview-feature   Run Preview Prisma commands
     --help, -h          Show additional information about a command

Examples

  Set up a new Prisma project
  $ prisma init

  Generate artifacts (e.g. Prisma Client)
  $ prisma generate

  Browse your data
  $ prisma studio

  Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
  $ prisma migrate dev

  Pull the schema from an existing database, updating the Prisma schema
  $ prisma db pull

  Push the Prisma schema state to the database
  $ prisma db push

  Validate your Prisma schema
  $ prisma validate

  Format your Prisma schema
  $ prisma format

  Display Prisma version info
  $ prisma version

  Display Prisma debug info
  $ prisma debug

With Bun (via bunx)

$ bunx --bun prisma --help
require.main === module false

With Bun (directly)

$ bun ../../packages/cli/build/index.js --help
require.main === module true
Remaining Output
◭  Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.io)

Usage

  $ prisma [command]

Commands

            init   Set up Prisma for your app
        generate   Generate artifacts (e.g. Prisma Client)
              db   Manage your database schema and lifecycle
         migrate   Migrate your database
          studio   Browse your data with Prisma Studio
        validate   Validate your Prisma schema
          format   Format your Prisma schema
         version   Displays Prisma version info
           debug   Displays Prisma debug info

Flags

     --preview-feature   Run Preview Prisma commands
     --help, -h          Show additional information about a command

Examples

  Set up a new Prisma project
  $ prisma init

  Generate artifacts (e.g. Prisma Client)
  $ prisma generate

  Browse your data
  $ prisma studio

  Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
  $ prisma migrate dev

  Pull the schema from an existing database, updating the Prisma schema
  $ prisma db pull

  Push the Prisma schema state to the database
  $ prisma db push

  Validate your Prisma schema
  $ prisma validate

  Format your Prisma schema
  $ prisma format

  Display Prisma version info
  $ prisma version

  Display Prisma debug info
  $ prisma debug

My best guess is that bun is treating being redirected via “bin” as not being hit directly.

Related Issues

In the schema.prisma file, in the generator client object at the very top, add output = "../generated" so that when you run bunx prisma generate, the definitions folder will now be placed in your projects root folder. also, after that line add this line too. binaryTargets = ["native", "debian-openssl-1-1.x"]

Then use your IDE to search for ANY mentions of "@prisma/client" in your source code and replace them with "generated". (See last paragraph first)

Don’t forget to run bunx prisma generate to create this new generated folder.

You’re welcome

- Bun v:1.0.28, Prisma v:5.10.2

– EDIT –

Seeing as I basically changed a folder’s location, I’m beginning to wonder if leaving it as it was before would still work for as long as we include binaryTargets = ["native", "debian-openssl-1-1.x"] in the schema file. The default value should be openssl-3 🤷 I’ll try this later tonight

Spent last two hours debugging why bunx prisma generate fails without error message. It ended up being missing nodejs.