4

I have a problem with local test functions in typescript. Now, I used npm run build && firebase serve --only functions to run local functions, but every change I made on the code, I need to run this command again to see the result. I want to view real-time change without having to build the typescript code every time. Is there a solution to this problem?

2 Answers2

11

The Firebase emulator will pick up changes to JavaScript automatically while it's running. Since you're using TypeScript, you will have to compile to JavaScript in order for the emulator to pick up the change. You have two main choices:

  • Run npm run build again after each change
  • Tell the TypeScript compile to "watch" your source files and compile them whenever there is a change. You can do that with npx tsc --watch.
karel
  • 5,489
  • 46
  • 45
  • 50
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
5

This is how I run both command together for my typescript functions

"serve": "tsc --watch & firebase serve --only functions"

That is my package.json and a npm scripts, so I can invoke it easily with one command and have it update whenever I make changes.

Mises
  • 4,251
  • 2
  • 19
  • 32
Jose
  • 1,959
  • 20
  • 21