Firebase-tools: `firebase serve` is serving old version

Created on 19 Nov 2018  路  7Comments  路  Source: firebase/firebase-tools

Hello!

I used firebase serve to learn how to run an express hello world app on firebase functions. It worked!

Then I changed the source and firebase serve is serving the old source... not sure why.

functions question

Most helpful comment

Hi there. I am not too concerned about Firebase Hosting as there is a build step that is outside of Firebase that is well known to the user. What I am referring to is Cloud Functions, which is built by Firebase. It is only built by Firebase on deploy, not on serve. I believe that it is proper for it to build on serve.

The workaround is to (cd functions && npm run build && firebase serve)

Cheers!

All 7 comments

First time I ran firebase serve it compiled my typescript project. Subsequent times it does not. Would this be considered a bug?

Thanks for bringing this up. This has started a bit of conversation within our team, but there is another path to solve this.

firebase serve simply serves static files. Typescript isn't directly usable by browsers, so it must be transpiled into Javascript. firebase serve will serve the static assets that are built by the typescript compilation process, and will update if those files are changed.

If two terminal windows are open, both in the same project, one running firebase serve --only hosting and one running tsc --watch, the typescript compiler will watch your workspace for any updates and rebuild the appropriate files while firebase serve will continue deploying the directly that is built.

Does this help?

Note: this is given in the context of specifically Firebase Hosting.

Hi there. I am not too concerned about Firebase Hosting as there is a build step that is outside of Firebase that is well known to the user. What I am referring to is Cloud Functions, which is built by Firebase. It is only built by Firebase on deploy, not on serve. I believe that it is proper for it to build on serve.

The workaround is to (cd functions && npm run build && firebase serve)

Cheers!

Good point - Javascript functions do "live update", but Typescript ones do not.

In practice, you could go into the functions directory and start a tsc --watch process there while developing in Typescript, and that will update your locally served functions as you go. That might be a good work around for the time being.

Also, I'm noting something else I just discovered: if I don't run npm run build in a new functions directory that was just initialized, it doesn't actually run start the functions.

I'm going to leave this to @thechenky to figure out the best course of action. Thanks for the report!

Sure thing. It should be noted that, as far as I remember, Typescript functions did compile on the first firebase serve but not subsequent ones.

Thanks for the feedback, @lukepighetti. I would advise going with the workaround for now as the team is a bit spread thin and the fix for this likely won't land for some time. I've created a bug for this in our internal tracker: 123266946. PRs are always welcome!

I'm going to close this issue as it relates to the legacy functions emulator backend. We've swapped this out so at the very least the nature of this bug has changed. I believe we've decided a good path forward (explicitly not handling watchers / compilation for compile-to-JS languages) so this is kinda a wontfix and kinda just outdated. If anyone feels like starting this discussion again, please open a new issue and we can discuss again.

Was this page helpful?
0 / 5 - 0 ratings