firebase-tools: firebase.json option "functions.source" is ignored by emulator
When using firebase serve --only functions
with firebase.json
like the following:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"function": "app"
}
]
},
"functions": {
"source": "./functions"
}
}
The Google Cloud Functions emulator doesn’t start correctly.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 16 (9 by maintainers)
@laurenzlong I get the part about having to execute the code, but what I don’t understand is the strict position of
node_modules
inside the functions root. If my project uses “my_functions” as its functions location, and has a package.json 1 or 2 levels above that in the project root, the emulator should be able to execute from my_functions which depends on node_modules to levels up if it follows the standard module resolvement strategy? (by just moving up a level and checking again).When deployment happens, the firebase tools can grab the folder that has the functions, and together with the package.json from the root it has everything it needs I would think. But maybe I’m missing something.
In any case, I solved things for myself by copying my package json into the babel built output. It works fine.
I also did an attempt with Webpack to bundle dependencies together with the code, but then the emulator wouldn’t see the functions anymore. Also the google libs were using expressions in require statements which webpack warned about, so I think that was step too far for now 😃
Anyway here is my setup for using babel:
PS: As you can see I also made firebase-tools a local dependency. This is because firebase-tools was already built on my system with a different node version, and the emulator doesn’t execute then. It needs to be built with node 6. Having it as a local dev dependency avoids conflicts like that.
What is the reason for not being able to point to a source outside of the project root directory?
android client -ios client
web client
source: "../br_functions/functions"
I have a web, android, and ios client. Needing the functions in the web client root directory creates many redundant steps to get emulators running for ios and android.
This is an old issue that affected the old functions emulator (version 6.x,
firebase serve
). I have successfully usedfunctions.source
withfirebase emulators:start
without issues so I am going to close this as fixed/obsolete.Also, having firebase-tools as a dev dependency is really clever!
Without the dot it is working fine for me.
But partially related to this, where can you find the options that go into firebase.json? I can’t seem to find any reference.
Also, I find it odd that firebase deploy requires a node_modules folder inside the functions source directory. I am using Babel to transpile the functions code, so I have a build directory separate from my source files. Firebase forces me to copy the package.json to the build output and run an install there before deploying. This seems unnecessary and redundant. Or I am misunderstanding the idea behind it. Can’t firebase deploy use the same module resolution as regular node? That would mean it moves to the parent directory and looks for node_modules there, until it finds what it’s looking for.