firebase / firebase/firebase-tools

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

Open
#5,814 3 comments 0 reactions 0 assignees View on GitHub
integration: web frameworks type: feature request
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [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. (/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.