adamjkb / bark

Materialized path extension for Prisma
https://prisma-extension-bark.gitbook.io
MIT License
42 stars 6 forks source link

Error when using Bark Middleware with Prisma on a custom output location #87

Open AmruthPillai opened 4 months ago

AmruthPillai commented 4 months ago

I have the following code:

prisma.schema

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/client"
}

libs/prisma.ts

const client = new PrismaClient({
    log: process.env.NODE_ENV === "development" ? ["error", "warn"] : ["error"],
  });

client.$extends(withBark({ modelNames: ["place"] }));

And when trying to build, I get the following error:

▲ Next.js 14.2.4
  - Environments: .env

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
   Collecting page data  ..Error: Cannot find module '.prisma/client/default'
Require stack:
- /node_modules/.pnpm/@prisma+client@5.15.1_prisma@5.15.1/node_modules/@prisma/client/default.js
- /.next/server/app/api/auth/callback/route.js
- /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/require.js
- /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/load-components.js
- /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/utils.js
- /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/worker.js
- /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/jest-worker/processChild.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/require-hook.js:55:36
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at mod.require (/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/node_modules/.pnpm/@prisma+client@5.15.1_prisma@5.15.1/node_modules/@prisma/client/default.js:2:6)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/node_modules/.pnpm/@prisma+client@5.15.1_prisma@5.15.1/node_modules/@prisma/client/default.js',
    '/.next/server/app/api/auth/callback/route.js',
    '/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/require.js',
    '/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/load-components.js',
    '/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/utils.js',
    '/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/worker.js',
    '/node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/compiled/jest-worker/processChild.js'
  ]
}

> Build error occurred
Error: Failed to collect page data for /api/auth/callback
    at /node_modules/.pnpm/next@14.2.4_@babel+core@7.24.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/build/utils.js:1268:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
   Collecting page data  . ELIFECYCLE  Command failed with exit code 1.

I have verified that it is because of this extensions, because I have disabled all other extensions and by commenting out Bark, the build succeeds again.

adamjkb commented 4 months ago

Thank you for reporting the issue! Could you provide a minimal reproduction of the issue?

I spun up one of the nextjs example for Prisma and it seem running without issue.

AmruthPillai commented 4 months ago

Sorry about the late reply. I'm sort of on a tight deadline at work so I don't have time to work on a small app demonstrating this issue, but once I have the time, I'll be sure to make one. I understand how important a reproducible PoC is for an open source dev.

Again, thank you so much for your efforts in making this middleware possible.

adamjkb commented 4 months ago

No worries! Thanks for taking the time to giving the package a go. Hopefully you won't need it for you deadline 😬

AmruthPillai commented 4 months ago

Actually I do 😅 so I removed the need to have a custom prisma location and continue to store it inside node modules as-is.

The only reason I moved it in the first place was that Prisma's deployment page suggested it here: https://arc.net/l/quote/firkehyb

Not sure if it's really that beneficial though.