trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

bug: Prisma 6.6+ Schema Folder Bug: Missing `--schema` Flag

Open cameronmema opened this issue 2 months ago • 3 comments

Provide environment information

System: OS: macOS 26.0 CPU: (16) arm64 Apple M4 Max Memory: 1018.27 MB / 48.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.7.0 - /Users/cm/.nvm/versions/node/v24.7.0/bin/node Yarn: 1.22.22 - /Users/cm/.nvm/versions/node/v24.7.0/bin/yarn npm: 11.5.1 - /Users/cm/.nvm/versions/node/v24.7.0/bin/npm bun: 1.2.21 - /Users/cm/.bun/bin/bun

Describe the bug

The prismaExtension fails with Prisma 6.6+ when using schema folders with names other than "schema" (e.g., models/, db/, etc.).

Expected: Prisma client generates successfully in production builds Actual: Prisma client is undefined, causing TypeError: Cannot read properties of undefined (reading 'findMany') in all tasks

The extension has two bugs:

  1. Hardcoded folder detection - Line 58 only checks endsWith("schema"), breaking valid custom folder names
  2. Missing --schema flag - Line 102 omits --schema flag for Prisma 6.6+ with outdated comment "Don't add the --schema flag or this will fail"

Per Prisma 6.6 docs:

As of v6.6.0, you must always explicitly specify the location of your Prisma schema folder.

Reproduction repo

https://gist.github.com/cameronmema/f86139133c28e2bec878cf374b942fe2

To reproduce

To reproduce

1. Setup (Monorepo with schema folder NOT named "schema")

packages/
  prisma/
    src/
      models/              ← Named "models" not "schema"
        schema.prisma      ← Generator + datasource
        user.prisma
        order.prisma
        ...
  jobs/
    trigger.config.ts

2. Configure Trigger.dev

// packages/jobs/trigger.config.ts
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  project: "proj_xxx",
  build: {
    extensions: [
      prismaExtension({
        version: "6.18.0",
        schema: "../../packages/prisma/src/models/schema.prisma",
        migrate: false,
      }),
    ],
  },
});

3. Deploy

bun run trigger deploy

4. Result

Build output shows files being copied:

Copying prisma schema from .../models/base.prisma to .../build/prisma/schema/base.prisma
Copying prisma schema from .../models/user.prisma to .../build/prisma/schema/user.prisma
...

Then fails:

> [build 6/7] RUN node node_modules/prisma/build/index.js generate:
Error: exit code: 1

Production runtime:

TypeError: Cannot read properties of undefined (reading 'findMany')
    at run (file:///src/tasks/my-task.ts:30:46)

Additional information

Additional information

The Two Bugs in Detail

Bug #1: packages/build/src/extensions/prisma.ts:58

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

Only detects folders ending with "schema". Breaks with models/, db/, or any custom name.

Bug #2: packages/build/src/extensions/prisma.ts:101-102

commands.push(
  `node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` 
  // Don't add the --schema flag or this will fail ← OUTDATED for Prisma 6.6+
);

The comment is wrong. Prisma 6.6+ requires the --schema flag.

The Fix (2 Lines)

Fix #1 - Better folder detection:

const parentDirName = dirname(this._resolvedSchemaPath).split("/").pop() || "";
const usingSchemaFolder = parentDirName === "schema" || parentDirName === "models";

Fix #2 - Add --schema flag for Prisma 6.6+:

if (usingSchemaFolder) {
  commands.push(
    `${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate --schema=./prisma/schema ${generatorFlags.join(" ")}`
  );
}

Workaround

I created a custom extension with these fixes: https://gist.github.com/cameronmema/f86139133c28e2bec878cf374b942fe2

Works perfectly, but users shouldn't need 240 lines of custom code for this.

Related

  • #1926 - Broader Prisma 6.6+ compatibility
  • Discord: @mfts reported EISDIR errors with schema folders
  • Discord: @Haakon reported undefined errors in monorepo with schema folders

Impact

Affects any monorepo using:

  • Prisma 6.6+
  • Multi-file schemas (schema folders)
  • Folder name other than "schema"

This is a breaking bug for common monorepo patterns where Prisma packages use descriptive folder names like models/, database/, db/, etc.

cameronmema avatar Nov 05 '25 10:11 cameronmema

A summary of the changes CodeRabbit can apply:

  • Update packages/build/src/extensions/prisma.ts to replace the hardcoded "schema" folder check with directory-based detection for arbitrary schema folder names and add the --schema=./prisma/schema flag to the Prisma generate command, fixing Prisma 6.6+ schema-folder generation while preserving single-file/backwards compatibility.

  • Update packages/build/src/extensions/prisma.ts to replace a fixed "schema" folder check with a dynamic schema-folder detection (compute schemaDir/parentDir and detect non-prisma subfolder with multiple .prisma files) and modify the Prisma generate command to include a --schema=./prisma/schema flag (for Prisma 6.6+ support).

  • [ ] Executed edits - (🔄 Check again to try again)

coderabbitai[bot] avatar Nov 05 '25 10:11 coderabbitai[bot]

[!CAUTION] The CodeRabbit agent's plans did not produce any file changes.

coderabbitai[bot] avatar Nov 05 '25 11:11 coderabbitai[bot]

[!CAUTION] The CodeRabbit agent's plans did not produce any file changes.

coderabbitai[bot] avatar Nov 05 '25 17:11 coderabbitai[bot]

@cameronmema has this been fixed by our new prisma extension updates: https://trigger.dev/changelog/prisma-7-integration

ericallam avatar Nov 21 '25 10:11 ericallam