firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Firebase functions emulator does not watch for changes.

Open NoahGav opened this issue 2 years ago • 7 comments

Environment info

firebase --version --> 11.1.0

node -v --> v16.15.1

npm -v --> 8.11.0

java -version --> java version "18.0.1.1" 2022-04-22

Platform:

Pop!_OS 22.04 LTS 64-bit

Steps to reproduce

1). run firebase init functions

2). Select Use an existing project and choose my project.

3). Select Javascript for the language.

4). Type N and press enter to not use eslint.

5). Type Y and press enter to install dependencies.

6). run firebase emulators:start or firebase emulators:start --only functions

7). Open functions/index.js and uncomment the helloWorld example, and save.

Expected behavior

I expect the functions emulator to detect the changes to the javascript code and to automatically apply those changes without restarting the emulator (manually).

Actual behavior

Nothing changes. I have to restart the emulator to use the helloWorld function. Or if the function was there when the emulator was started I have to restart it to see changes made to the function itself. If I make changes to the firestore.rules file while running the firestore emulator those changes are registered without restarting the emulator(s) like it's supposed to.

!!!!! Notes !!!!!

No matter what I do it does not work on my main machine (linux). I tried it in a windows 11 virtual machine with the same versions of node, npm, firebase-tools, and java and it works. Clearly something is misconfigured on my linux, but I have been unable to figure out what. Here are the videos showing my results.

Linux: https://www.dropbox.com/s/j54j8or1fw88mgc/not-working.mp4?dl=0

Windows: https://www.dropbox.com/s/c3412h77x1efged/working-windows.mp4?dl=0

NoahGav avatar Jun 29 '22 10:06 NoahGav

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jun 29 '22 10:06 google-oss-bot

@NoahGav I don't know what Pop!_OS is, but maybe you want to try this trick:

Set the environment variable

CHOKIDAR_USEPOLLING=true

This helps when running Firebase Emulators under Docker. Its volume mapping looks like network drives to Docker client OS, and the normal watching isn't applied to them.

Could be something else, of course. Just trying to help.

akauppi avatar Jul 04 '22 22:07 akauppi

As far as I know this isn't a supported feature, nor have I seen it planned anywhere. The only thing that hot-reloads right now are the rules files when changed.

I wrote up a script and posted it on a related issue https://github.com/firebase/firebase-tools/issues/3034#issuecomment-1132379004 that reloads the emulators (after waiting or killing their process) when my output folder changes. It's not entirely straight forward, and I utilize Docker.

dereekb avatar Jul 10 '22 06:07 dereekb

@dareekb No, it does work. I just had to switch to windows 11 instead of using pop os. For some reason the functions emulator did not work with hot reload on pop os.

NoahGav avatar Jul 10 '22 23:07 NoahGav

Sorry, I didn't realize you were just using Javascript (which seems to have working function reloading). I found another thread I was thinking of here: https://github.com/firebase/firebase-tools/issues/758

dereekb avatar Jul 11 '22 04:07 dereekb

We're currently in the early phases of rearchitecting our emulator to be a better foundation for the future and any investment we make at the moment into hot-reloading would need to be completely reimagined for our upcoming new system. Hot reloading (including tsc watch) is on my wishlist of features, but it'll be a while before we have the resources to commit to it. Even when we do have a new emulator with potential hotloading, it's very possible that we will only support hot-modifying existing functions and not discovering new functions after emulator boot-up.

inlined avatar Jul 29 '22 17:07 inlined

We're currently in the early phases of rearchitecting our emulator to be a better foundation for the future and any investment we make at the moment into hot-reloading would need to be completely reimagined for our upcoming new system. Hot reloading (including tsc watch) is on my wishlist of features, but it'll be a while before we have the resources to commit to it. Even when we do have a new emulator with potential hotloading, it's very possible that we will only support hot-modifying existing functions and not discovering new functions after emulator boot-up.

So everytime we make a change on our functions, we need to restart the emulator(s)?

Psycarlo avatar Sep 09 '22 19:09 Psycarlo

We're currently in the early phases of rearchitecting our emulator to be a better foundation for the future and any investment we make at the moment into hot-reloading would need to be completely reimagined for our upcoming new system. Hot reloading (including tsc watch) is on my wishlist of features, but it'll be a while before we have the resources to commit to it. Even when we do have a new emulator with potential hotloading, it's very possible that we will only support hot-modifying existing functions and not discovering new functions after emulator boot-up.

@inlined That's awesome! Looking foward for that! Let me help a little bit making sure a proper feedback regarding this typescript workflow feature reaches you: Not only we have to invoke tsc as part of our 'build' process, since it doesn't have 'first-class' support, but also there is a huge issue when it comes to the emulators in this scenario. You can't 'invoke' the emulators UI separating just the functions emulators. If you attempt to do that, another instance of the UI running the others emulators will conflict. That means your functions testing workflow now includes reloading the whole emulators suite everytime you change a typescript module that is part of a cloud function. Goes without saying that is horrible right now... I hope the feedback helps and I'm looking foward for the changes!

euthiago avatar Feb 06 '23 18:02 euthiago

Since this issue is pretty old and was originally about watching javascript changes (not tsc watch) that are implemented, I'm going to close out it out.

@euthiago Unfortunately, we haven't added tsc -w into the emulator start command yet. You can get hot reloading by starting watch mode before kicking off the emulators. Here's where we mention it in our docs - https://firebase.google.com/docs/functions/local-emulator#run_the_emulator_suite - thanks

colerogers avatar Feb 07 '23 19:02 colerogers

To be clear for people that come after this, for handling transpilation and running emulators, you need to run two different processes for these, instead of combining them into one package.json script (i.e. "serve": "tsc -w && firebase emulators:start" (because tsc -w will prevent the emulators from ever running).

So start tsc -w in one terminal session, then your emulators in another.

@colerogers looking forward to this being added to the emulator start command! It'd be helpful if this current caveat were pointed out more clearly in the Use Typescript for Cloud Functions docs.

jketcham avatar Jul 20 '23 20:07 jketcham

To add on to @jketcham's solution, you can alternatively use "emulate":"tsc --watch & firebase:emulators:start"

apetta avatar Nov 04 '23 13:11 apetta