firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.98k stars 918 forks source link

Allow for a gcp-build script to be persisted in the code-generated Cloud Function for web frameworks deploys #5814

Open parasj opened 1 year ago

parasj commented 1 year ago

[REQUIRED] Environment info

Mac OS 13.3.1 firebase --version: 11.30.0

[REQUIRED] Test case

Deploy the sample Next.js Prisma app: https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes

Follow the next.js instructions for Firebase Hosting: https://firebase.google.com/docs/hosting/frameworks/nextjs

[REQUIRED] Steps to reproduce

Upon deploying the function, check Google Cloud Logging where you will see an error:

DEFAULT 2023-05-09T03:46:20.606352Z Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
DEFAULT 2023-05-09T03:46:20.606369Z In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
DEFAULT 2023-05-09T03:46:20.606376Z at new PrismaClient (/workspace/node_modules/.prisma/client/index.js:3:11)
DEFAULT 2023-05-09T03:46:20.606383Z at 8047 (/workspace/.next/server/chunks/8439.js:16:37)
DEFAULT 2023-05-09T03:46:20.606389Z at __webpack_require__ (/workspace/.next/server/webpack-api-runtime.js:25:42)
DEFAULT 2023-05-09T03:46:20.606396Z at 8439 (/workspace/.next/server/chunks/8439.js:39:69)
DEFAULT 2023-05-09T03:46:20.606402Z at __webpack_require__ (/workspace/.next/server/webpack-api-runtime.js:25:42)
DEFAULT 2023-05-09T03:46:20.606409Z at __webpack_exec__ (/workspace/.next/server/pages/api/auth/[...nextauth].js:56:39)
DEFAULT 2023-05-09T03:46:20.606414Z at /workspace/.next/server/pages/api/auth/[...nextauth].js:57:67
DEFAULT 2023-05-09T03:46:20.606420Z at __webpack_require__.X (/workspace/.next/server/webpack-api-runtime.js:177:21)
DEFAULT 2023-05-09T03:46:20.606426Z at /workspace/.next/server/pages/api/auth/[...nextauth].js:57:47
DEFAULT 2023-05-09T03:46:20.606432Z at Object.<anonymous> (/workspace/.next/server/pages/api/auth/[...nextauth].js:60:3)

Proposed fix

After tracing through the documentation, it seems like the issue can be fixed by modifying the Next.js build step: https://github.com/firebase/firebase-tools/blob/ab7af34d8d96ce9f2b84feacc6c52e5bca30f223/src/frameworks/next/index.ts#L417C75-L492 with code to add the following line to the generated package.json file:

{
    "scripts":
    ...
        "gcp-build": "CI=1 && npx prisma generate"
    }
}

As reference, see the added gcp-build step that is added to: https://github.com/prisma/ecosystem-tests/tree/94506e7b2abaf916b2f0413fef858a0ec77dda9b/platforms-serverless/firebase-functions

I also recommend not deleting the "gcp-build" script from package.json here: https://github.com/firebase/firebase-tools/blob/ab7af34d8d96ce9f2b84feacc6c52e5bca30f223/src/frameworks/index.ts#L361

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

okaforcj commented 1 year ago

@jamesdaniels please are there any updates or work arounds on this? we want to have a step to add prisma generate but currently we're not seeing anyway to do it "gcp-build": "CI=1 && npx prisma generate". works for regular firebase functions but not for the nextjs integrations

@parasj where you able to get this to work correctly?

hamiltonchua commented 10 months ago

Up ! I'm seeing this as well. No way to add prisma generate during build.