Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gmathieu opened this issue Nov 17, 2024 · 2 comments

Comments

@gmathieu
Copy link

gmathieu commented Nov 17, 2024

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/@[email protected][email protected]/node_modules/@trigger.dev/build/dist/commonjs/extensions/prisma.js:55:19)
      at notifyExtensionOnBuildComplete
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/build/extensions.js:16:33)
      at async buildWorker
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/build/buildWorker.js:70:21)
      at async _deployCommand
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/commands/deploy.js:120:27)
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/commands/deploy.js:77:16
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/cli/common.js:54:28
      at async wrapCommandAction
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/cli/common.js:40:12)
      at async deployCommand
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/commands/deploy.js:76:12)
      at async
  file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/node_modules/trigger.dev/dist/esm/commands/deploy.js:71:13
      at async handleTelemetry
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/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/[email protected][email protected]/node_modules/trigger.dev/dist/esm/commands/deploy.js:69:9)
      at async Command.parseAsync
  (/Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected]/node_modules/commander/lib/command.js:935:5)
      at async main
  (file:///Users/guillaume/alephic/trigger-prisma-bug/node_modules/.pnpm/[email protected][email protected]/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/[email protected] --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/[email protected]"] }),
    ]
  }
})

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

@Cirr0e
Copy link

Cirr0e commented Nov 25, 2024

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/[email protected]"] 
      }),
    ]
  }
})

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!

@RobertHH-IS
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants