azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Hot reload

Open ahmedelnably opened this issue 5 years ago • 47 comments

ahmedelnably avatar Apr 26 '19 17:04 ahmedelnably

I'm really eager to get this. It's so nice to be able to test Functions super fast in the Azure Portal, we need that locally as well!

janmechtel avatar Jan 17 '20 09:01 janmechtel

So still no news on this?

galgrunfeld-madtrix avatar Jan 21 '20 09:01 galgrunfeld-madtrix

Everyone interested in this should consider switching the language to c# script for development purposes, works like a charm: https://stackoverflow.com/questions/59783914/how-to-speed-up-debugging-c-sharp-azure-function-locally-is

janmechtel avatar Jan 24 '20 10:01 janmechtel

@janmechtel even though it works well on C# scripts, its far from ideal because it goes against other features that we've asking so much for Az Func like pre-compiled projects, ReadyToRun (not available yet) and most important, Dependency Injection support.

Its almost one year old issue. @ahmedelnably do you have any news on whether this would be supported or not? This would REALLY streamline the support. Right now we have Collectible Assemblies support in .Net Core, so we are able to load and unload assemblies at runtime so that could be supported even if you are not using the regular watch feature from dotnet CLI.

galvesribeiro avatar Apr 12 '20 11:04 galvesribeiro

In case anyone is interested, I've found a workaround. You have to create an MSBuild target which runs the functions host and watch against this target: In the csproj add

  <Target Name="RunFunctions">
    <Exec Command="func start" />
  </Target>

and later run it with dotnet watch msbuild /t:RunFunctions. So far works well for me.

marcin-dardzinski avatar Aug 05 '20 07:08 marcin-dardzinski

Would some workaround be on JavaScript/TypeScript environment?

seed-of-apricot avatar Sep 12 '20 19:09 seed-of-apricot

I would also like to know how a hot reloaded or watched development environment can be setup in node. Any clues or leads?

hlz avatar Sep 29 '20 10:09 hlz

Would some workaround be on JavaScript/TypeScript environment?

I would also like to know this for Typescript...

MattL-NZ avatar Oct 27 '20 01:10 MattL-NZ

Fwiw I have found out that it is possible running func startand tsc -w in parallel under JS/TS. Changes made to function code are picked up directly by the local function host so there is no need for restarting. Except for changes in function.json files. Could elaborate more if someone finds that interesting.

hlz avatar Oct 27 '20 08:10 hlz

Fwiw I have found out that it is possible running func startand tsc -w in parallel under JS/TS. Changes made to function code are picked up directly by the local function host so there is no need for restarting. Except for changes in function.json files. Could elaborate more if someone finds that interesting.

the big issue I have with this is the horrendous errors. Since its trying to run compiled JS, you're left with trying to figure out where it went wrong in TS. Would be nice to use ts-node for development

edit: Created an issue for this Azure/azure-functions-nodejs-worker#736

grbspltt avatar Nov 18 '20 21:11 grbspltt

the big issue I have with this is the horrendous errors. Since its trying to run compiled JS, you're left with trying to figure out where it went wrong in TS. Would be nice to use ts-node for development

Yeah this is far from ideal. Same problem arises when debugging code.

edit: Created an issue for this Azure/azure-functions-nodejs-worker#736

Hope this will make it's way into the extension.

hlz avatar Nov 19 '20 11:11 hlz

Would this include live reload in Ubuntu WSL2 for the Python runtime?

ryan-theta avatar May 06 '21 06:05 ryan-theta

Hi! What's the status on this? Dotnet has this for years through dotnet watch run. Should be easy to add especially for azure functions in C#, no?

KevinFerm avatar May 19 '21 15:05 KevinFerm

Curious if this is being triaged at all. It is an obvious productivity killer. I'm using the out-of-the-box TypeScript Azure Function debug task from vscode. For every single change, I have to kill the entire running function, reinstalling npm package (why do we need this?), recompile typescript. That's 10-20 seconds gone. Please consider improving the default debug experience

  • Install npm only when necessary
  • Fix the "restart" behavior. Currently, it just kills the function without restarting.
  • Give us a well documented CLI that integrates with npm scripts, instead of relying on VSCode launch tasks. This opens up the tool for interoperability with other change detection/recompiling tools such as ts-node and ts-node-dev.

chuanqisun avatar May 20 '21 20:05 chuanqisun

@chuanqisun If you use the start script provided with func init this works out of the box with Typescript.

But maybe your problem is related to the issue I just opened: Azure/azure-functions-host#7795

panmona avatar Jul 02 '21 19:07 panmona

same issue here, let's make it fix on typescript azure function

chenxizhang avatar Aug 21 '21 01:08 chenxizhang

I saw that "tsc -w" is working fine, but the "func start" maybe have some problem, it just not able to detect the changes on the dist folder

chenxizhang avatar Aug 21 '21 01:08 chenxizhang

I have exactly the same behavior as @chenxizhang: When I run npm run start: tsc -w does update the files in dist folder, but func is not actually using those changes, so I have to kill the task and run npm run start again.

Yvand avatar Sep 02 '21 15:09 Yvand

I'm developing a ts api and this is driving me crazy. Please, implement this for god's sake. 🤦‍♂️

nerblock avatar Sep 16 '21 00:09 nerblock

I found how to make it work in my TypeScript project: I removed variables WEBSITE_MOUNT_ENABLED and WEBSITE_RUN_FROM_PACKAGE from my local.settings.json. Now, npm run start immediately serves the changes when I save the .ts file. Those variables were added when I executed func azure functionapp fetch-app-settings.

Yvand avatar Sep 16 '21 09:09 Yvand

wow, thanks to @Yvand, it works for me now. You save many time for me, man

chenxizhang avatar Sep 16 '21 12:09 chenxizhang

The workaround from @marcin-dardzinski is great, but is there a more native way to do it with dotnet 6? Something like dotnet watch run or func watch start?

iSeiryu avatar Nov 12 '21 21:11 iSeiryu

I second what @iSeiryu said. Afterall, hot reload was successfully kept in NET6 also for non Visual Studio users. How can this be integrated into the function core tools?

mdddev avatar Nov 22 '21 08:11 mdddev

Agreed, this should absolutely be added as a feature (especially with Functions - 4 and/or .NET 6 projects)

a3y3 avatar Feb 25 '22 20:02 a3y3

@a3y3 agreed; since it works, it seems like the team should just formalize it.

CharlieDigital avatar Mar 12 '22 02:03 CharlieDigital

@CharlieDigital how did you get it to work with vs code? Sorry if I misunderstood.

mdddev avatar Mar 12 '22 10:03 mdddev

@mdddev I used @marcin-dardzinski 's workaround as described above in this discussion.

CharlieDigital avatar Mar 12 '22 15:03 CharlieDigital

Still waiting for an official support. But for those who use Node.js runtime, here is my workaround

package.json

{
  "scripts": {
    "start": "concurrently npm:start:*",
    "start:tsc": "tsc -w --preserveWatchOutput",
    "start:func": "nodemon --watch dist --delay 1 --exec \"func start -p 7072\""
  },
  "devDependencies": {
    "concurrently": "^7.0.0",
    "nodemon": "^2.0.15",
    "typescript": "^4.5.5"
  }
}

To use breakpoint debug in VS Code, update .vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Azure Function",
      "request": "launch",
      "runtimeArgs": ["run-script", "start"],
      "runtimeVersion": "14",
      "runtimeExecutable": "npm",
      "skipFiles": ["<node_internals>/**"],
      "type": "pwa-node",
      "console": "integratedTerminal"
    }
  ]
}

Only known issue is that the function will immediate reload after initial start. And if you project depends on other files in the directory, you'd need to add new watch parameter manually. Everything else is working.

chuanqisun avatar Mar 14 '22 16:03 chuanqisun

@mdddev I used @marcin-dardzinski 's workaround as described above in this discussion.

Hi @CharlieDigital , thanks for hinting me in that direction. I tried this, however, it seems that this is only exiting the process and invoking func start automatically on a code change. I was under the assumption that hot reload injects the code changes into the running process.

mdddev avatar Mar 17 '22 13:03 mdddev

@mdddev one can dream!

CharlieDigital avatar Mar 17 '22 13:03 CharlieDigital