1

I'm authoring an Azure Function in TypeScript in VS Code. If I start the Azure Functions host locally (either by using F5 in VS Code or by running "npm start" from the command line), everything runs fine. However, when I make and save a change to my TypeScript code, the local Azure Function host doesn't pick up on the change/restart the function. I have to manually stop/restart it.

The default "start" entry in package.json appears to be trying to achieve this:

"start": "npm run start:host & npm run watch"

But running "npm start" does not appear to cause the restart-on-change behavior. I may not be looking in the right place, but it doesn't seem like the second command is even executing at all. That said, even if I have tsc watch running from inside VS Code while "func start" is running elsewhere, the Azure Function host still seems to need to be manually restarted after the transpiling happens.

Is there a way to make the local Azure Function host automatically restart whenever I make changes to my TypeScript code? Am I missing something about how this is supposed to work?

Thanks!

Auth Infant
  • 1,760
  • 1
  • 16
  • 34
  • Both of those commands should be running (in separate sub shells because of `&`) and it seems to be working fine for me. Have you made any changes to your `tsconfig.json` or any of the `function.json` files? – PramodValavala Mar 26 '19 at 09:36
  • No, I have not made any notable changes. In fact, if I just create a whole new function project (using "func init" in an empty directory) and a new function (using "func function new"), the auto-update functionality does not work. It appears to only ever run the local function runtime and never the tsc watch command. – Auth Infant Apr 01 '19 at 16:37

1 Answers1

1

From doing more research, it seems like the issue is that the single ampersand (&) in the package.json does not run the commands in parallel on Windows. The Windows cmd shell runs commands separated by & in serial. So while this command may work as intended in bash or something else, it does not work when run on Windows.

It looks like you could fix this in a Windows-specific way by using something like what is mentioned in one of the answers here: https://stackoverflow.com/a/36275359/7117308

"start": "start npm run start:host & start npm run watch"

Or, to avoid extra cmd windows:

"start": "start npm run watch & npm run start:host"

As I mentioned, that's a Windows-specific solution, of course. That same stackoverflow post I referenced above shows options for platform-agnostic ways of achieving this.

Auth Infant
  • 1,760
  • 1
  • 16
  • 34