You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Requesting Cloud Functions for Firebase to support pnpm workspaces #5911
I am facing a pretty serious situation in which I cannot deploy/fix any functions to my project (pnpm based).
Trying to deploy fail with this error:
Build failed: This project is using pnpm but you have not included the Functions Framework in your dependencies. Please add it by running: 'pnpm add @google-cloud/functions-framework'.; Error ID: 5b6dc8b5
Functions deploy had errors with the following functions:
bigben(us-central1)
i functions: cleaning up build files...
Error: There was an error deploying functions
The proposed fix (adding @google-cloud/functions-framework) does not help.
Reacted by Diego, Ángel Cervera Claudio, Sanath, Nakano as a Service, HMothaffar, Seiji Kasahara, shinaBR2, Drew Johnson, kanyamo, Seanitzel(Sean Ray Dvir) and 1 more
Firebase does not officially support pnpm. In order to deploy your functions, we need to load your code using a script we install with the firebase-functions SDK. Pnpm workspaces make it hard to do this sort of bootstrapping of your code.
changed the title [-]Cannot deploy functions anymore - firebase complaining about pnpm[/-][+]Requesting Cloud Functions for Firebase to support pnpm[/+]on May 31, 2023
changed the title [-]Requesting Cloud Functions for Firebase to support pnpm[/-][+]Requesting Cloud Functions for Firebase to support pnpm workspaces[/+]on May 31, 2023
I have been using pnpm with firebase functions since a couple of years without any problem (I am not using workspace - just pnpm as the dependency manager).
The fact that functions deploy properly when I remove pnpm-lock.yaml smells a false positive check somewhere.
@taeold - can this be retriaged to bug as the success of the deploment relies on the existence ot pnpm.lock.yaml only (e.g. I can deply when the file does not exist, and inversely).
Firebase does not officially support pnpm. In order to deploy your functions, we need to load your code using a script we install with the firebase-functions SDK. Pnpm workspaces make it hard to do this sort of bootstrapping of your code.
So for sure, this information should be, at least, in the documentation. It is a huge limitation. This one, and also the one related to workspaces.
Note: If a package-lock.json, yarn.lock, or pnpm-lock.yaml file is found within your project, that lock file will be respected when dependencies are installed using npm ci, yarn install or pnpm install.
Doesn't this document mean that Firebase supports pnpm?
I've encountered the exact same problem and removing pnpm-lock.yaml fixed it for me too.
I confirmed that without pnpm-lock.yaml firebase CLI used npm instead of pnpm, that is the behavior described in the document.
@christophe-g
FYI: For me adding @google-cloud/functions-framework as root dependencies worked, while adding it as devDependencies or workspace package's dependencies didn't. I have no idea why functions-framework is needed.
@colerogers - any chance to have this reviewed and fixed ?
Please note that this is not a feature request - but a bug as it was previously working as expected (possible to deploy with pnpm as stated in the documentation).
Hi @christophe-g apologies for the delayed response. So I did a little digging on this issue and the error is not actually coming from the Firebase CLI, but instead the Cloud Build job.
Since a Firebase function is actually a Google Cloud Function under the hood, we send your source code over to Cloud Build and that job uses Buildpacks to build source to a container image.
I dug a little bit deeper and found that around the time that you started seeing this behavior (end of may), the buildpacks team published support for pnpm. They state that you would need to have the @google-cloud/functions-framework dependency installed, like the error gives.
Since it sounds like you still have this issue with the dependency installed, I think opening a bug on their repo would be a good next step. I'm sorry that this has taken so long and that you have to jump through more hoops just to get this resolved. Thanks
In case you'd like to deploy only an isolated part of your pnpm monorepo to firebase, have a look at this solution It also lets you deploy to firebase from multiple packages.
In case you like to avoid adding the @google-cloud/functions-framework dependency, the isolate-package forceNpm configuration lets you output an npm package-lock.json file instead, so you can deploy it as if your code does not depend on pnpm. The lockfile versions should match the pnpm lockfile, and I think that's all that matters really.
Do you know about the (possibly undocumented) --ignore-workspace flag for pnpm? Using this I can install dependencies in a subfolder based on a dummy package.json residing there, and generate a new, stand-alone pnpm lockfile, even while still inside the workspace heirarchy.
For example:
#!/bin/bash
# File: deploy-node
if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "Usage: deploy-node <source-code-directory> <output-directory>"
echo "Run this command from within the package you wish to deploy"
echo "The entry point in the source code directory is assumed to be index.ts"
echo "Example: deploy-node src dist"
echo "Warning: The output directory will be emptied!"
exit 1
fi
if [[ -f $2 ]]; then
echo "Error: $2 is a file!"
exit 2
fi
mkdir -p $2
rm -rf $2/*
cp .firebaserc $2
cp firebase.json $2
cp $REPO_ROOT/.nvmrc $2
cp package.template.json $2/package.json
bundle-node $1 $2
cd $2
pnpm install --ignore-workspace
pnpm run --ignore-workspace
I get the local dependencies in by bundling them with esbuild:
#!/bin/bash
# File: bundle-node
if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "Usage: bundle-node <source-code-directory> <output-directory>"
echo "The entry point in the source code directory is assumed to be index.ts"
echo "Example: bundle-node src dist"
exit 1
fi
esbuild $1/index.ts --bundle \
--platform=node \
--target=node20 \
--outdir=$2 \
--out-extension:.js=.cjs \
--external:firebase-functions \
--external:firebase-admin \
--allow-overwrite \
--sourcemap=external \
--legal-comments=none
No copying, linking, zipping, vendoring or any of that nonsense. esbuild inlines my custom code right into the output file. The Google dependencies are left out, and Cloud Build takes care of installing them. So this generates a very small bundle.
@johndunderhill I tried it at some point in the beginning and somehow concluded that it wasn't doing what I needed. I think it doesn't take the original lockfile into account. It was quite a long and winding road for me to get to the isolated lockfile for pnpm, so I don't quite remember everything.
Eventually, the process of adapting the lockfile is quite straightforward, and also fast, so I don't think there's much to gain from using an alternative approach.
Change this:
"@types/package" : "workspace:1.0.0"
To
"@types/package" : "file:1.0.0"
Before build and deployment and after
Reverse in postdeploy.
pre-deploy.js
constfs=require("fs");fs.readFile("./package.json","utf8",(err,data)=>{if(err){console.error("Erreur lors de la lecture du fichier package.json :",err);return;}constpackageJson=JSON.parse(data);packageJson.devDependencies["@types/gcrm"]="file:1.0.0";fs.writeFile("./package.json",JSON.stringify(packageJson,null,2),"utf8",(err)=>{if(err){console.error("Erreur lors de l'écriture dans le fichier package.json :",err,);return;}console.log("Le fichier package.json a été mis à jour avec succès.");},);});
Does the same but reverse process in post-deploy.js (or add conditionning for switch also)
I think the relevant discussion that is still open is #653 , no?
In the meantime, you can use isolate-package if you deploy all in one go (currently only mentioned here) or use the firebase-tools-with-isolate fork, with which you can deploy and emulate multiple packages/domains simultaneously.
I use isolate-package also for non-firebase deployments, like docker containers.
Activity
christophe-g commentedon May 30, 2023
Hmmm, removing
pnpm-lock.yamlin thefunctionssource folder results in a successful deployment. Not too sure what to make of it.inlined commentedon May 31, 2023
Firebase does not officially support pnpm. In order to deploy your functions, we need to load your code using a script we install with the firebase-functions SDK. Pnpm workspaces make it hard to do this sort of bootstrapping of your code.
[-]Cannot deploy functions anymore - firebase complaining about pnpm[/-][+]Requesting Cloud Functions for Firebase to support pnpm[/+][-]Requesting Cloud Functions for Firebase to support pnpm[/-][+]Requesting Cloud Functions for Firebase to support pnpm workspaces[/+]christophe-g commentedon Jun 1, 2023
I have been using pnpm with firebase functions since a couple of years without any problem (I am not using workspace - just pnpm as the dependency manager).
The fact that functions deploy properly when I remove
pnpm-lock.yamlsmells a false positive check somewhere.christophe-g commentedon Jul 18, 2023
@taeold - can this be retriaged to
bugas the success of the deploment relies on the existence otpnpm.lock.yamlonly (e.g. I can deply when the file does not exist, and inversely).angelcervera commentedon Aug 10, 2023
So for sure, this information should be, at least, in the documentation. It is a huge limitation. This one, and also the one related to workspaces.
m-shaka commentedon Aug 30, 2023
https://firebase.google.com/docs/functions/handle-dependencies
Doesn't this document mean that Firebase supports pnpm?
I've encountered the exact same problem and removing
pnpm-lock.yamlfixed it for me too.I confirmed that without
pnpm-lock.yamlfirebase CLI used npm instead of pnpm, that is the behavior described in the document.m-shaka commentedon Aug 31, 2023
@christophe-g
FYI: For me adding
@google-cloud/functions-frameworkas root dependencies worked, while adding it as devDependencies or workspace package's dependencies didn't. I have no idea why functions-framework is needed.I deployed 1st gen functions using pnpm workspace
christophe-g commentedon Sep 12, 2023
@colerogers - any chance to have this reviewed and fixed ?
Please note that this is not a feature request - but a bug as it was previously working as expected (possible to deploy with pnpm as stated in the documentation).
Thanks.
colerogers commentedon Sep 21, 2023
Hi @christophe-g apologies for the delayed response. So I did a little digging on this issue and the error is not actually coming from the Firebase CLI, but instead the Cloud Build job.
Since a Firebase function is actually a Google Cloud Function under the hood, we send your source code over to Cloud Build and that job uses Buildpacks to build source to a container image.
I dug a little bit deeper and found that around the time that you started seeing this behavior (end of may), the buildpacks team published support for pnpm. They state that you would need to have the
@google-cloud/functions-frameworkdependency installed, like the error gives.Since it sounds like you still have this issue with the dependency installed, I think opening a bug on their repo would be a good next step. I'm sorry that this has taken so long and that you have to jump through more hoops just to get this resolved. Thanks
christophe-g commentedon Sep 21, 2023
Thanks a lot @colerogers - appreciated.
I will try to install @google-cloud/functions-framework again and update all related dep. Will post the results here.
0x80 commentedon Dec 17, 2023
In case you'd like to deploy only an isolated part of your pnpm monorepo to firebase, have a look at this solution It also lets you deploy to firebase from multiple packages.
johndunderhill commentedon Dec 30, 2023
@0x80 Great work on
isolate. Very nice. We'll be trying it in a pnpm monorepo next week. I really appreciate your efforts.0x80 commentedon Dec 30, 2023
In case you like to avoid adding the
@google-cloud/functions-frameworkdependency, the isolate-packageforceNpmconfiguration lets you output an npm package-lock.json file instead, so you can deploy it as if your code does not depend on pnpm. The lockfile versions should match the pnpm lockfile, and I think that's all that matters really.johndunderhill commentedon Jan 3, 2024
Thanks, @0x80.
Do you know about the (possibly undocumented)
--ignore-workspaceflag for pnpm? Using this I can install dependencies in a subfolder based on a dummypackage.jsonresiding there, and generate a new, stand-alone pnpm lockfile, even while still inside the workspace heirarchy.For example:
I get the local dependencies in by bundling them with
esbuild:No copying, linking, zipping, vendoring or any of that nonsense.
esbuildinlines my custom code right into the output file. The Google dependencies are left out, and Cloud Build takes care of installing them. So this generates a very small bundle.The dummy
package.jsonlooks like this:The
firebase.jsonincludes:I can re-run
bundle-nodewhile the emulator is running and it will 'hot reload' my cloud function for testing.0x80 commentedon Jan 5, 2024
@johndunderhill I tried it at some point in the beginning and somehow concluded that it wasn't doing what I needed. I think it doesn't take the original lockfile into account. It was quite a long and winding road for me to get to the isolated lockfile for pnpm, so I don't quite remember everything.
Eventually, the process of adapting the lockfile is quite straightforward, and also fast, so I don't think there's much to gain from using an alternative approach.
solarpush commentedon Mar 13, 2024
I had the same problem and finally found a solution
In my case it's only types and therefore a devellopement dependency but the library is well built in the modules nodes so it should work for the rest.
I finally found the solution in the google doc...
Google docs local packages
Change this:
"@types/package" : "workspace:1.0.0"
To
"@types/package" : "file:1.0.0"
Before build and deployment and after
Reverse in postdeploy.
pre-deploy.js
Does the same but reverse process in post-deploy.js (or add conditionning for switch also)
firebase.json
Don't forget to create the script on your package.json
Bye
Sandbye commentedon Jan 13, 2026
I still think this is highly relevant, and an issue worth reopening.
SaketQuora commentedon Feb 8, 2026
issue still persists
0x80 commentedon Feb 8, 2026
I think the relevant discussion that is still open is #653 , no?
In the meantime, you can use isolate-package if you deploy all in one go (currently only mentioned here) or use the firebase-tools-with-isolate fork, with which you can deploy and emulate multiple packages/domains simultaneously.
I use isolate-package also for non-firebase deployments, like docker containers.