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
Functions discovery breaks with yarn/npm/pnpm workspaces #5517
firebase init functions
>Don't set up a default project
>Typescript
>ESLint: No
>Install Deps: No
Add {
"projects": {
"default": "default"
}
} to /.firebaserc
Uncomment helloWorld function
yarn set version berry
Add [nodeLinker: node-modules](https://yarnpkg.com/configuration/yarnrc#nodeLinker) in your .yarnrc.yml file
Add "workspaces": ["functions"] to /package.json
cd functions
yarn build
cd ..
yarn up [email protected]
[REQUIRED] Steps to reproduce
firebase functions:shell
[REQUIRED] Expected behavior
Functions found by firebase and run in emulator and deploy properly, as they do before yarn up [email protected] is ran
[REQUIRED] Actual behavior
i functions: Loaded functions:
No functions emulated.
Were you able to successfully deploy your functions?
No, I receive the error:
The following functions are found in your project but do not exist in your local source code:
*
Reacted by Meril, Filipe Mariano, Atle Sjønøst, Marcel, Mathias Gilson, Seanitzel(Sean Ray Dvir), Adrian Liechti, Tobias Goulden Schultz and Joshua Sosso (Deprecated)
I get the same problem, but it doesn't seem like a yarn 2 problem, as it's the same with yarn 1 (in my nx repo). Still staying on 3.24.1, not sure where the fix belongs, in firebase-tools or in firebase-functions.
changed the title [-]Functions not found using v4 and Yarn 2[/-][+]firebase-tools does not find functions while using yarn workspaces (firebase-functions v4)[/+]on Oct 25, 2022
It turns out the problem is that it started looking for a node_modules in the same folder as the functions source folder.
So if the node_modules is in an upper level for shared usage, this issue happens.
I confirmed it by the fact that adding a symbolic link in the functions source folder to the actual location of node_modules, got it working again.
I'm making this the master bug for a series of issues with the same underlying cause:
During functions v1, we simply require your code and look for __trigger. During v2, we now load your code as an HTTPS server and read a manifest. In the 4.0 release we removed support for __trigger because it has not been used since the first public release of firebase-functions/v2.
Unfortunately this uncovered an very bad issue: our code to decide whether to use the v1 strategy or the v2 strategy depends on npm list, which isn't returning accurate results when customers are using workspaces. This tells the CLI to fall back to the v1 strategy, which the 4.0 SDK does not support. To fix this, we have two parallel prongs of attack:
We're adding __trigger back to the 4.0 SDK because it provides a safety net for many of our customers. This change should roll out soon. This will not be enough to use all of v2 though because v2's format is necessary to represent the additional complexity of v2. Thus:
We're still in the early phases of research for adding workspace awareness if not strong support. This will let us detect that you have the 4.0 functions SDK and launch the webserver that hosts your code and tells us what to support.
Reacted by Joshua Sosso (Deprecated), Meril and Andrew Krippner
changed the title [-]firebase-tools does not find functions while using yarn workspaces (firebase-functions v4)[/-][+]Functions discovery breaks with yarn/npm/pnpm workspaces[/+]on Oct 31, 2022
We reverted back the change that broke many users in v4.0.2 of the firebase functions sdk.
We are working on a long term solution to make the function deployment aware of workspaces and other dev toolings that changes where npm packages are installed (e.g. pnpm).
In the meantime, please give 4.0.2 a try. Would appreciate your feedbacks.
We reverted back the change that broke many users in v4.0.2 of the firebase functions sdk.
We are working on a long term solution to make the function deployment aware of workspaces and other dev toolings that changes where npm packages are installed (e.g. pnpm).
In the meantime, please give 4.0.2 a try. Would appreciate your feedbacks.
After the issue firebase-tools #5448 was resolved, the new error is: ⬢ functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Please file a bug on Github (https://github.com/firebase/firebase-tools/).
As you can see, the sdkPath is complicated. I believe this happened because of pnpm's unique way of structuring packages which require.resolve does not expect.
I have found a solution specifically for pnpm which requires that firebase-functions must be listed as either a dependency or devDependency at the workspace level, otherwise pnpm will not create the symlink for the 'normal' node_modules path
The fix for me has been to remove the .pnpm path and everything that follows
Proposed code changes: add a replace chain to the decalaration for sdkPath (this line):
For those who are not willing to wait (like me), you can manually go to <workspace_root>/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/index.js.
The line to change is in the serveAdmin function.
I can confirm this. I got this error also after updating to [email protected]. After fixing sdkPath manually as @DibyodyutiMondal suggested functions were loaded successfully.
@DibyodyutiMondal thank you for your wonderful, detailed writeup! And thank you @diginikkari for confirming the fix.
Crafting a fix based on your findings, and I'm curious if your Firebase project directory == workspace directory. I'm trying to come up with a semi-rebost way to detect the workspace directory, and wondering if I can rely on project directoy being the same as the workspace directory.
in my case my firebase.json is located in my (NX) monorepo root. Functions are build to dist/functions/. Functions config in firebase.json is following:
"functions": {
"predeploy": ["pnpm nx run functions:lint", "pnpm nx run functions:build"],
"source": "dist/apps/functions"
},
node_modules - the only node_modules in the entire workspace. All projects in the workspace use this folder for imports, i.e, projects don't have separate node_modules inside their folders.
All the above are relative to workspace root
As far as I can tell, using require.resolve and works quite well. It's simply pnpm's way of symlinking that's causing it get confused. I don't know how yarn workspaces are structured. I'd think the easiest way to deal with this would be be allow us to set an 'sdkPath' in firebase.json and nudge firebase in the right direction.
Yes, it means that users may have an extra setting to think about, but if we keep the current behaviour as a fallback in case that config is not provided, then majority of users can go on as if nothing happened and people who have unusual project structures will also find it very easy. We simply specify the folder path and move on.
Activity
google-oss-bot commentedon Oct 24, 2022
I found a few problems with this issue:
atsjo commentedon Oct 25, 2022
I get the same problem, but it doesn't seem like a yarn 2 problem, as it's the same with yarn 1 (in my nx repo). Still staying on 3.24.1, not sure where the fix belongs, in firebase-tools or in firebase-functions.
#5145
MathiasGilson commentedon Oct 25, 2022
same issue here I had to roll back to [email protected] to for firebase serve to detect my functions
otherwise, I get a
✔ functions: Loaded functions definitions from source: .[-]Functions not found using v4 and Yarn 2[/-][+]firebase-tools does not find functions while using yarn workspaces (firebase-functions v4)[/+]swissspidy commentedon Oct 28, 2022
Same issue here with npm workspaces (not yarn)
miguel-leon commentedon Oct 31, 2022
It turns out the problem is that it started looking for a
node_modulesin the same folder as the functions source folder.So if the
node_modulesis in an upper level for shared usage, this issue happens.I confirmed it by the fact that adding a symbolic link in the functions source folder to the actual location of
node_modules, got it working again.inlined commentedon Oct 31, 2022
I'm making this the master bug for a series of issues with the same underlying cause:
During functions v1, we simply
requireyour code and look for__trigger. During v2, we now load your code as an HTTPS server and read a manifest. In the 4.0 release we removed support for__triggerbecause it has not been used since the first public release offirebase-functions/v2.Unfortunately this uncovered an very bad issue: our code to decide whether to use the v1 strategy or the v2 strategy depends on
npm list, which isn't returning accurate results when customers are using workspaces. This tells the CLI to fall back to the v1 strategy, which the 4.0 SDK does not support. To fix this, we have two parallel prongs of attack:__triggerback to the 4.0 SDK because it provides a safety net for many of our customers. This change should roll out soon. This will not be enough to use all of v2 though because v2's format is necessary to represent the additional complexity of v2. Thus:[-]firebase-tools does not find functions while using yarn workspaces (firebase-functions v4)[/-][+]Functions discovery breaks with yarn/npm/pnpm workspaces[/+]taeold commentedon Nov 7, 2022
We reverted back the change that broke many users in v4.0.2 of the firebase functions sdk.
We are working on a long term solution to make the function deployment aware of workspaces and other dev toolings that changes where npm packages are installed (e.g. pnpm).
In the meantime, please give 4.0.2 a try. Would appreciate your feedbacks.
andrewkrippner commentedon Nov 7, 2022
My functions deploy now after upgrading to v4.0.2
michaelangeloio commentedon Nov 12, 2022
FYI I use the following set up with NX (this in in
apps/server/project.json:For running the functions locally.
And then to detect properly, I use the following in firebase.json, where
distis the compiled JS from thebuildNX target.DibyodyutiMondal commentedon Feb 1, 2023
Update as of
After the issue firebase-tools #5448 was resolved, the new error is:
⬢ functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Please file a bug on Github (https://github.com/firebase/firebase-tools/).I see that work is in progress at:
firebase-tools/src/deploy/functions/runtimes/node/index.ts
Lines 173 to 185 in 416d034
In my specific case I use pnpm and nx
The above variables reolve to:
As you can see, the
sdkPathis complicated. I believe this happened because of pnpm's unique way of structuring packages whichrequire.resolvedoes not expect.I have found a solution specifically for pnpm which requires that firebase-functions must be listed as either a dependency or devDependency at the workspace level, otherwise pnpm will not create the symlink for the 'normal' node_modules path
The fix for me has been to remove the
.pnpmpath and everything that followsProposed code changes: add a
replacechain to the decalaration forsdkPath(this line):For those who are not willing to wait (like me), you can manually go to
<workspace_root>/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/index.js.The line to change is in the
serveAdminfunction.diginikkari commentedon Feb 5, 2023
I can confirm this. I got this error also after updating to [email protected]. After fixing sdkPath manually as @DibyodyutiMondal suggested functions were loaded successfully.
taeold commentedon Feb 6, 2023
@DibyodyutiMondal thank you for your wonderful, detailed writeup! And thank you @diginikkari for confirming the fix.
Crafting a fix based on your findings, and I'm curious if your Firebase project directory == workspace directory. I'm trying to come up with a semi-rebost way to detect the workspace directory, and wondering if I can rely on project directoy being the same as the workspace directory.
diginikkari commentedon Feb 6, 2023
in my case my
firebase.jsonis located in my (NX) monorepo root. Functions are build todist/functions/. Functions config infirebase.jsonis following:DibyodyutiMondal commentedon Feb 6, 2023
For me workspace directory != functions directory
apps/cloud-functiions- ts source codedist/apps/cloud-funtions- js outputfirebase.json- confignode_modules- the only node_modules in the entire workspace. All projects in the workspace use this folder for imports, i.e, projects don't have separate node_modules inside their folders.All the above are relative to workspace root
As far as I can tell, using
require.resolveand works quite well. It's simply pnpm's way of symlinking that's causing it get confused. I don't know how yarn workspaces are structured. I'd think the easiest way to deal with this would be be allow us to set an 'sdkPath' in firebase.json and nudge firebase in the right direction.Yes, it means that users may have an extra setting to think about, but if we keep the current behaviour as a fallback in case that config is not provided, then majority of users can go on as if nothing happened and people who have unusual project structures will also find it very easy. We simply specify the folder path and move on.
Lookup more places to find Firebase Functions SDK in developer's work…