Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"firebase serve" in firebase functions is not running the latest changes

I am playing with firebase functions. Works fine when deploying to firebase server using command firebase deploy --only functions. However, I would like to test my functions locally before deploy to server of course. What I see running firebase serve is that the functions "deployed" locally have not the latest changes I did in indext.ts - are running the last builded version, which are in index.js.

My question is, How do I manual build my firebase functions project to test them locally with latest changes? Should firebase serve autobuild the project before deploy it locally? For me, it sounds like a bug.

like image 239
lordneru Avatar asked Jul 19 '18 07:07

lordneru


People also ask

What is firebase serve command?

When using firebase serve , your app interacts with an emulated backend for your Hosting content and config (and optionally functions) but your real backend for all other project resources. Note: By running this command with the --only hosting flag, you're only emulating your Hosting content and config.

What script should be run before every deploy firebase?

The firebase init command creates a firebase. json configuration file in the root of your project directory. The firebase. json file is required to deploy assets with the Firebase CLI because it specifies which files and settings from your project directory are deployed to your Firebase project.


2 Answers

firebase serve doesn't seem to be running npm build. But if you look inside functions/package.json, you can see there is already a serve script there that performs npm run build && firebase serve --only functions. So if you just do:

cd functions
npm run serve

You can build and serve without having to do two separate commands.

like image 64
JYeh Avatar answered Sep 28 '22 11:09

JYeh


If you want to reload the changes to your TypeScript when running firebase serve or firebase functions:shell, all you have to do is build your project again using npm script that was created for you when you initialized the project (see package.json):

cd functions
npm run build

This will transpile your TypeScript to JavaScript, and the changes to the JavaScript will get picked up by the emulator automatically.

Also, if you are a more advanced TypeScript user, you can run tsc --watch to automatically compile TS to JS when source files change on disk. You can read more about that in this blog.

like image 43
Doug Stevenson Avatar answered Sep 28 '22 12:09

Doug Stevenson