Skip to content

bug: prismaExtension's version detection only works when "@prisma/client" is added to additionalPackages #1480

Closed as not planned

Description

@gmathieu

Provide environment information

System:
OS: macOS 15.1
CPU: (11) arm64 Apple M3 Pro
Memory: 133.08 MB / 18.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.18.0 - /opt/homebrew/opt/node@20/bin/node
npm: 10.8.2 - /opt/homebrew/opt/node@20/bin/npm
pnpm: 9.12.3 - /opt/homebrew/opt/node@20/bin/pnpm

Describe the bug

Running pnpm dlx trigger.dev@latest deploy fails when using prismaExtension's default config.

Based on this doc, the prismaExtension should automatically detect the installed version. Without a version, the deployment succeeds and silently reports an error:

% pnpm trigger deploy

Trigger.dev (3.2.0)
------------------------------------------------------
┌  Deploying project
│
◇  Retrieved your account details for ...
│
◇  Successfully built project
✘ [ERROR] Failed to apply extension PrismaExtension onBuildComplete Error: PrismaExtension could not determine the version of @prisma/client. It's possible that the @prisma/client was not used in the project. If this isn't the case, please provide a version in the PrismaExtension options.

      at PrismaExtension.onBuildComplete
  (/Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/@trigger.dev+build@3.2.0_typescript@5.6.3/node_modules/@trigger.dev/build/dist/commonjs/extensions/prisma.js:55:19)
      at notifyExtensionOnBuildComplete
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/build/extensions.js:16:33)
      at async buildWorker
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/build/buildWorker.js:70:21)
      at async _deployCommand
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/commands/deploy.js:120:27)
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/commands/deploy.js:77:16
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/cli/common.js:54:28
      at async wrapCommandAction
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/cli/common.js:40:12)
      at async deployCommand
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/commands/deploy.js:76:12)
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/commands/deploy.js:71:13
      at async handleTelemetry
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/cli/common.js:30:9)
      at async Command.<anonymous>
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/commands/deploy.js:69:9)
      at async Command.parseAsync
  (/Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/commander@9.5.0/node_modules/commander/lib/command.js:935:5)
      at async main
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/trigger.dev@3.2.0_typescript@5.6.3/node_modules/trigger.dev/dist/esm/index.js:5:5)


│
◇  Successfully deployed version 20241117.8
│
└  Version 20241117.8 deployed with 1 detected task 

When adding version: "5.22.0", the deployment fails entirely:

% pnpm trigger deploy  

Trigger.dev (3.2.0)
------------------------------------------------------
┌  Deploying project
│
◇  Retrieved your account details for ...
│
◇  Successfully built project
▲ [WARNING] prismaExtension could not resolve the DATABASE_URL environment variable. Make sure you add it to your environment variables. See our docs for more info: https://trigger.dev/docs/deploy-environment-variables


│
◇  Failed to deploy project
│
└  Error: Error building image. Full build logs have been saved to /var/folders/4j/sp9fwh5s369b28x_jjckbgd40000gn/T/trigger-Z2WsDu/build-gwivrttk.log

Here's a snippet of the build error:

------
> [build 6/7] RUN node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma:
#17 0.456 Prisma schema loaded from prisma/schema.prisma
#17 0.579 Error: Command failed with ENOENT: pnpm add @prisma/client@5.22.0 --silent
#17 0.579 spawn pnpm ENOENT
------
Error: failed to solve: process "/bin/sh -c node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma" did not complete successfully: exit code: 1

Workaround

Adding "@prisma/client" to additionalPackages fixes the issue:

import { defineConfig } from "@trigger.dev/sdk/v3";
import { additionalPackages } from "@trigger.dev/build/extensions/core";
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";

export default defineConfig({
  build: {
    extensions: [
      prismaExtension({ schema: "prisma/schema.prisma" }),
      additionalPackages({ packages: ["@prisma/client@5.22.0"] }),
    ]
  }
})

Reproduction repo

https://github.com/gmathieu/trigger-prisma-bug

To reproduce

Note: Don't worry about DATABASE_URL warnings, we're only testing the deployment cycle.

Scenario 1: silent failure

  • run pnpm trigger deploy

Scenario 2: build failure with version

Scenario 3: successful deployment with additionalPackages

Note: additionalPackages properly populates the manifest's externals here, so version can be omitted.

Additional information

No response

Activity

  1. Cirr0e commented on Nov 25, 2024

    @Cirr0e

    Hi! I understand the issue you're experiencing with the prismaExtension's version detection. This appears to be a known limitation in how the extension currently works with Prisma dependencies.

    Here's how to resolve this issue:

    1. Update your trigger.config.ts to use both the prismaExtension and additionalPackages together:
    import { defineConfig } from "@trigger.dev/sdk/v3";
    import { additionalPackages } from "@trigger.dev/build/extensions/core";
    import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
    
    export default defineConfig({
      build: {
        extensions: [
          prismaExtension({ 
            schema: "prisma/schema.prisma"
            // Note: You don't need to specify version when using additionalPackages
          }),
          additionalPackages({ 
            packages: ["@prisma/client@5.22.0"] 
          }),
        ]
      }
    })

    This configuration ensures that:

    • The Prisma schema is properly loaded
    • The correct version of @prisma/client is available during build
    • The version detection will work correctly

    Be aware that:

    • You should match the version of @prisma/client to what's in your project's package.json
    • Make sure your DATABASE_URL environment variable is properly configured for deployment

    This is currently the recommended workaround until the version detection functionality is improved in a future release.

    Let me know if you need any clarification or run into any other issues!

  2. RobertHH-IS commented on Dec 14, 2024

    @RobertHH-IS

    the build also fails if using prismaSchemaFolder extension.

    If schema.prisma
    `generator client {
    provider = "prisma-client-js"
    previewFeatures = ["postgresqlExtensions", "prismaSchemaFolder", "fullTextSearchPostgres"]
    }

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

    And then you create other.prisma and user.prisma.. everything works fine in NextJS.. however trigger.dev build says that schema.prisma is empty and errors out.

  3. rharkor commented on Feb 3, 2025

    @rharkor
    Contributor

    the build also fails if using prismaSchemaFolder extension.

    If schema.prisma `generator client { provider = "prisma-client-js" previewFeatures = ["postgresqlExtensions", "prismaSchemaFolder", "fullTextSearchPostgres"] }

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

    And then you create other.prisma and user.prisma.. everything works fine in NextJS.. however trigger.dev build says that schema.prisma is empty and errors out.

    Yes, I'm currently having the same issue..

  4. matt-aitken commented on Feb 3, 2025

    @matt-aitken
    Member

    @rharkor can you share your trigger.config file?

    We do support the folders, by following the convention that the enclosing folder should be called schema. You can see the code here:

    const usingSchemaFolder = dirname(this._resolvedSchemaPath).endsWith("schema");

    I know that people are using this, so maybe there's some new case here we don't deal with

  5. rharkor commented on Feb 4, 2025

    @rharkor
    Contributor

    @rharkor can you share your trigger.config file?

    We do support the folders, by following the convention that the enclosing folder should be called schema. You can see the code here:

    trigger.dev/packages/build/src/extensions/prisma.ts

    Line 115 in 6f52b00
    const usingSchemaFolder = dirname(this._resolvedSchemaPath).endsWith("schema");

    I know that people are using this, so maybe there's some new case here we don't deal with

    Hey thanks for the reply, I've found the issue, it was because I am currently using multiple databases so I finally made my own small extension to handle that, if anyone have the same problem feel free to check the code below (please note that the paths aren't dynamic)

    import fs from "fs/promises"
    import path from "path"
    
    import { BuildExtension } from "@trigger.dev/build"
    
    export function prismaExtension(): BuildExtension {
      return {
        name: "prisma-extension",
        externalsForTarget(target) {
          if (target === "dev") {
            return []
          }
          return ["@prisma/client", "@prisma/engines"]
        },
        onBuildComplete: async (context, manifest) => {
          context.logger.debug("Copying the prisma schema to the output directory")
          //* Main database
          await fs.cp(
            path.join(__dirname, "../../../../../packages/database/main/prisma"),
            path.join(manifest.outputPath, "main-prisma", "prisma"),
            { recursive: true }
          )
          //* Logs database
          await fs.cp(
            path.join(__dirname, "../../../../../packages/database/logs/prisma"),
            path.join(manifest.outputPath, "logs-prisma", "prisma"),
            { recursive: true }
          )
    
          context.logger.debug(`Adding the prisma layer with the following commands`, {
            commands: ["cd main-prisma && npx prisma generate", "cd logs-prisma && npx prisma generate"],
            env: {},
            dependencies: {
              prisma: "latest",
            },
          })
          context.addLayer({
            id: "prisma",
            commands: ["cd main-prisma && npx prisma generate", "cd logs-prisma && npx prisma generate"],
            dependencies: {
              prisma: "latest",
            },
            build: {
              env: {},
            },
          })
        },
      }
    }
  6. matt-aitken commented on Feb 4, 2025

    @matt-aitken
    Member

    @rharkor nice!

  7. matt-aitken commented on Aug 29, 2026

    @matt-aitken
    Member

    The Prisma extension has been rewritten. It now detects the Prisma version without additionalPackages. Closing as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions