firebase cli cannot deploy functions when using pnpm, turborepo along with firebase-functions@4.0.0
See original GitHub issueEnvironment info
firebase-tools: v11.15.0
firebase-functions: v4.0.1
Platform: macos (local dev), ubuntu (ci)
Test case
Steps to reproduce
Deploy firebase functions for nodejs with firebase-tools and firebase-functions versions noted above.
Expected behavior
Cloud functions deploy successfully
Actual behavior
Firebase functions triggers are not parsed, resulting in no functions being deployed. If you are using the --force flag, your functions will be deleted.
tldr; I upgraded from firebase-functions@3.24.1 to firebase-functions@4.0.1, resulting in my function triggers not being parsed and all my firebase functions being deleted (and an outage for our customers 🔥). I think firebase-tools should prevent users from deploying with firebase-functions@4
I thought it was safe for me to upgrade to firebase-functions@v4 as their release notes did not mention any incompatibility with the current version of firebase-tools. Upon upgrading my CI did a deploy, deleting all my functions.
The cause is that my function triggers were no longer recognised by firebase-tools, and I have set my CI to deploy with --force, resulting in no functions deployed and all my functions being deleted.
I traced the source of the issue, being that firebase-functions@v4 no longer adds __trigger to the cloud functions triggers, but firebase-tools uses this property to discover function triggers in extractTriggers.js. This is mentioned in the release notes for firebase-functions “Removed __trigger object on function handlers.”, although it’s not immediately obvious that means that function triggers will no longer be recognised at all.
I did notice that the peerDependencies of firebase-tools does not allow firebase-functions@4 but unfortunately my tools did not prevent the upgrade (I accepted the upgrade from renovate bot after reading the release notes and deeming it a safe upgrade).
I would like to suggest that my issue could have been avoided if firebase-tools prevented users from deploying with firebase-functions@v4. There is already a check to make sure an incompatible (lower) version of firebase-functions is not used.
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:10 (5 by maintainers)
Top Related StackOverflow Question
Same issue with npm workspaces.
Hi @taeold, before deploying to Cloud Functions for Firebase we bundle our source code into a format more close to a typical npm setup. This is the only way we’ve been able to reliably deploy to Cloud Functions for Firebase, and we used to use a similar mechanism when we previously used yarn (classic) and yarn (2.x, 3.x).
For context, one of the the main reasons we use a pnpm monorepo setup is so we can share code by making packages that are not published to the registry, but are referenced and linked locally by pnpm (workspace dependencies, which use a
workspace:*version specifier). To get a Cloud Functions for Firebase package to deploy, we use a special bundling and deployment process that emulates a regular single package npm setup.Bundling process:
The result is a self contained package that can be deployed to Cloud Functions for Firebase. Note this output package does not contain any references to the rest of the monorepo.
Deployment process:
functions.sourceinfirebase.jsonto the build output folder.pnpm install --shamefully-hoistinside the build output folder, this installs dependencies in a folder structure that is (mostly) equivalent to an npm or yarn install.firebase deploy, otherwise loading the code for trigger parsing can crash.npm installthat will be performed by Cloud Build, as the Node.js Cloud Functions buildpack does not have support for pnpm.firebase deploy --only functions:<namespace>in the main package.Here is an example of the file structure for context.
Let me know if I can provide anything further.
FYI I noticed there are a few other tools being mentioned in this thread, to be clear my setup only uses pnpm, the notable differences from a regular npm setup being the use of workspace dependencies and the node_modules folder structure used by pnpm. I am not using turborepo, nx, or any other monorepo build tool.