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

Prisma fixes #452

Merged
merged 6 commits into from
Feb 17, 2025
Merged

Prisma fixes #452

merged 6 commits into from
Feb 17, 2025

Conversation

haydenbleasel
Copy link
Owner

@haydenbleasel haydenbleasel commented Feb 16, 2025

Copy link

vercel bot commented Feb 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-forge 🛑 Canceled (Inspect) Feb 17, 2025 4:31pm
next-forge-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 4:31pm
next-forge-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 17, 2025 4:31pm

@barsketis
Copy link
Contributor

what is the build error in vercel for next-forge-app after this last commit?

@haydenbleasel
Copy link
Owner Author

Hey @barsketis, on the second-to-last commit, these were the build statuses:

✅ app
❌ api
✅ web

API had the warning:

.../node_modules/@prisma/client postinstall$ node scripts/postinstall.js
.../node_modules/@prisma/client postinstall: prisma:warn We could not find your Prisma schema in the default locations (see: https://pris.ly/d/prisma-schema-location).
.../node_modules/@prisma/client postinstall: If you have a Prisma schema file in a custom path, you will need to run
.../node_modules/@prisma/client postinstall: `prisma generate --schema=./path/to/your/schema.prisma` to generate Prisma Client.
.../node_modules/@prisma/client postinstall: If you do not have a Prisma schema file yet, you can ignore this message.
.../node_modules/@prisma/client postinstall: Done

it also had the error:

api:build: Failed to compile.
api:build:
api:build: ../../packages/database/index.ts:6:1
api:build: Module not found: Can't resolve './generated/client'
api:build: 4 | import { PrismaNeon } from '@prisma/adapter-neon';
api:build: 5 | import ws from 'ws';
api:build: > 6 | import { PrismaClient } from './generated/client';
api:build: | ^
api:build: 7 | import { keys } from './keys';
api:build: 8 |
api:build: 9 | const globalForPrisma = global as unknown as { prisma: PrismaClient };
api:build:
api:build: https://nextjs.org/docs/messages/module-not-found
api:build:
api:build: Import trace for requested module:
api:build: ./app/cron/keep-alive/route.ts
api:build:
api:build:
api:build: > Build failed because of webpack errors

On the latest commit:

❌ app
✅ api
✅ web

app has the error:

app:build: Failed to compile.
app:build:
app:build: ../../packages/database/index.ts:6:1
app:build: Module not found: Can't resolve './generated/client'
app:build: 4 | import { PrismaNeon } from '@prisma/adapter-neon';
app:build: 5 | import ws from 'ws';
app:build: > 6 | import { PrismaClient } from './generated/client';
app:build: | ^
app:build: 7 | import { keys } from './keys';
app:build: 8 |
app:build: 9 | const globalForPrisma = global as unknown as { prisma: PrismaClient };
app:build:
app:build: https://nextjs.org/docs/messages/module-not-found
app:build:
app:build: Import trace for requested module:
app:build: ./app/(authenticated)/page.tsx
app:build:
app:build:
app:build: > Build failed because of webpack errors

I'm thinking that last commit fixed the warning, but the ./generated/client issue feels either ephemeral or a race condition.

Possibly related is prisma/prisma#7234 (comment)

@barsketis
Copy link
Contributor

barsketis commented Feb 17, 2025

Heres what I did to get the build to pass vercel, im not sure if this is optimal but might help

packages package.json

{
  "scripts": {
    "analyze": "prisma generate --no-hints --schema=./prisma/schema.prisma",
    "postinstall": "prisma generate --no-hints --schema=./prisma/schema.prisma",
    "build": "prisma generate --no-hints --schema=./prisma/schema.prisma",
    "clean": "git clean -xdf .cache .turbo dist node_modules",
    "typecheck": "tsc --noEmit --emitDeclarationOnly false"
  },
}

turbo.json modified the outputs to include the generated folder

{
  "$schema": "https://turbo.build/schema.json",
  "globalDependencies": ["**/.env.*local"],
  "ui": "tui",
  "envMode": "loose",
  "tasks": {
    "build": {
      "dependsOn": ["^build", "test"],
      "outputs": [".next/**", "!.next/cache/**", ".basehub/**", "**/generated/**"]
    },
  }
}

@barsketis
Copy link
Contributor

The vercel build had prisma errors after loggin in

⨯ Error [PrismaClientInitializationError]: 
Invalid `prisma.page.findMany()` invocation:


Prisma Client could not locate the Query Engine for runtime "rhel-openssl-3.0.x".

I tried adding in the binary query engine in the prisma file, but it did not work, so I reverted your removal of the helper library installed (@prisma/nextjs-monorepo-workaround-plugin), and had to make some minor changes to get it to compile on vercel. It appears to be working now with no errors

import withBundleAnalyzer from "@next/bundle-analyzer"

import { PrismaPlugin } from "@prisma/nextjs-monorepo-workaround-plugin"
import type { NextConfig } from "next"

const otelRegex = /@opentelemetry\/instrumentation/

export const config: NextConfig = {
  images: {
    formats: ["image/avif", "image/webp"],
    remotePatterns: [
      {
        protocol: "https",
        hostname: "img.clerk.com",
      },
    ],
  },

  // biome-ignore lint/suspicious/useAwait: rewrites is async
  async rewrites() {
    return [
      {
        source: "/ingest/static/:path*",
        destination: "https://us-assets.i.posthog.com/static/:path*",
      },
      {
        source: "/ingest/:path*",
        destination: "https://us.i.posthog.com/:path*",
      },
      {
        source: "/ingest/decide",
        destination: "https://us.i.posthog.com/decide",
      },
    ]
  },

  webpack(config, { isServer }) {
    if (isServer) {
      config.plugins = config.plugins || []
      config.plugins.push(new PrismaPlugin())
    }

    config.ignoreWarnings = [{ module: otelRegex }]

    return config
  },

  // This is required to support PostHog trailing slash API requests
  skipTrailingSlashRedirect: true,
}

export const withAnalyzer = (sourceConfig: NextConfig): NextConfig =>
  withBundleAnalyzer()(sourceConfig)

@DaveMitten
Copy link

The vercel build had prisma errors after loggin in

⨯ Error [PrismaClientInitializationError]: 
Invalid `prisma.page.findMany()` invocation:


Prisma Client could not locate the Query Engine for runtime "rhel-openssl-3.0.x".

I tried adding in the binary query engine in the prisma file, but it did not work, so I reverted your removal of the helper library installed (@prisma/nextjs-monorepo-workaround-plugin), and had to make some minor changes to get it to compile on vercel. It appears to be working now with no errors

import withBundleAnalyzer from "@next/bundle-analyzer"

import { PrismaPlugin } from "@prisma/nextjs-monorepo-workaround-plugin"
import type { NextConfig } from "next"

const otelRegex = /@opentelemetry\/instrumentation/

export const config: NextConfig = {
  images: {
    formats: ["image/avif", "image/webp"],
    remotePatterns: [
      {
        protocol: "https",
        hostname: "img.clerk.com",
      },
    ],
  },

  // biome-ignore lint/suspicious/useAwait: rewrites is async
  async rewrites() {
    return [
      {
        source: "/ingest/static/:path*",
        destination: "https://us-assets.i.posthog.com/static/:path*",
      },
      {
        source: "/ingest/:path*",
        destination: "https://us.i.posthog.com/:path*",
      },
      {
        source: "/ingest/decide",
        destination: "https://us.i.posthog.com/decide",
      },
    ]
  },

  webpack(config, { isServer }) {
    if (isServer) {
      config.plugins = config.plugins || []
      config.plugins.push(new PrismaPlugin())
    }

    config.ignoreWarnings = [{ module: otelRegex }]

    return config
  },

  // This is required to support PostHog trailing slash API requests
  skipTrailingSlashRedirect: true,
}

export const withAnalyzer = (sourceConfig: NextConfig): NextConfig =>
  withBundleAnalyzer()(sourceConfig)

Does this mean that there has been a resolution in the build error for the prisma db issue, or are we needing further action?

@haydenbleasel
Copy link
Owner Author

@DaveMitten that change simply reverts my change, I don't think it will fix the issues linked.

I've asked the Prisma team to take a look.

@haydenbleasel
Copy link
Owner Author

Also for context, this PR implements Prisma's officially documented way of working with Turborepo. Unsure how the plugin fits into this but it would be nice to have better documentation.

@ankur-arch
Copy link

Hi @barsketis 👋 ,

Are you using a custom output path with the helper library?

@barsketis
Copy link
Contributor

barsketis commented Feb 17, 2025

Hi @barsketis 👋 ,

Are you using a custom output path with the helper library?

Yes that is correct, I merged his branch in and added back the library to get rid of the binary issue during the vercel build, but I kept the generated client code. Otherwise prisma would not export the types and throw a "no page type found" during compiling the vanilla repo with vercel.

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
  output          = "../generated/client"
}

I do agree with hayden, the prisma documentation is not accurate for how to deal with turbo repos, I tried many different combinations they recommended and defaulted back to utilizing their helper library. Im not sure what this library does however, it might be redundant with haydens changes for the output file.

 webpack(config, { isServer }) {
    if (isServer) {
      config.plugins = config.plugins || []
      config.plugins.push(new PrismaPlugin())
    }

    config.ignoreWarnings = [{ module: otelRegex }]

    return config
  },

  // This is required to support PostHog trailing slash API requests
  skipTrailingSlashRedirect: true,
}

I havent tested this solution yet but it doesnt seem optimal.
prisma/prisma#22519

 "compilerOptions": {
    "paths": {
      "@prisma/client": ["./node_modules/@prisma/client"]
    }

@barsketis
Copy link
Contributor

Here are the changes I did to get the App repo working on vercel
#453

barsketis and others added 3 commits February 17, 2025 11:21
@haydenbleasel
Copy link
Owner Author

Seems to deploy just fine now! Nice work @barsketis

@haydenbleasel haydenbleasel merged commit dcee038 into main Feb 17, 2025
8 checks passed
@haydenbleasel haydenbleasel deleted the prisma-fixes branch February 17, 2025 16:32
Copy link

🚀 PR was released in v3.2.26 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
4 participants