Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload #1239

Open
ahmedelnably opened this issue Apr 26, 2019 · 49 comments
Open

Hot reload #1239

ahmedelnably opened this issue Apr 26, 2019 · 49 comments

Comments

@ahmedelnably
Copy link
Contributor

No description provided.

@janmechtel
Copy link

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!

@galgrunfeld-madtrix
Copy link

So still no news on this?

@janmechtel
Copy link

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

@galvesribeiro
Copy link

galvesribeiro commented Apr 12, 2020

@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.

@marcin-dardzinski
Copy link

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.

@seed-of-apricot
Copy link

Would some workaround be on JavaScript/TypeScript environment?

@hlz
Copy link

hlz commented Sep 29, 2020

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

@MattL-NZ
Copy link

Would some workaround be on JavaScript/TypeScript environment?

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

@hlz
Copy link

hlz commented Oct 27, 2020

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.

@grbspltt
Copy link

grbspltt commented Nov 18, 2020

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

@hlz
Copy link

hlz commented Nov 19, 2020

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.

@ryan-theta
Copy link

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

@KevinFerm
Copy link

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?

@chuanqisun
Copy link

chuanqisun commented May 20, 2021

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.

doggy8088 added a commit to doggy8088/TaiwanHolidayFuncApp that referenced this issue Jun 12, 2021
@panmona
Copy link

panmona commented Jul 2, 2021

@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

@chenxizhang
Copy link

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

@chenxizhang
Copy link

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

@Yvand
Copy link

Yvand commented Sep 2, 2021

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.

@nerblock
Copy link

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

@Yvand
Copy link

Yvand commented Sep 16, 2021

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.

@chenxizhang
Copy link

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

@iSeiryu
Copy link

iSeiryu commented Nov 12, 2021

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?

@mdddev
Copy link

mdddev commented Nov 22, 2021

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?

@a3y3
Copy link

a3y3 commented Feb 25, 2022

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

@CharlieDigital
Copy link

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

@mdddev
Copy link

mdddev commented Mar 12, 2022

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

@CharlieDigital
Copy link

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

@chuanqisun
Copy link

chuanqisun commented Mar 14, 2022

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.

@mdddev
Copy link

mdddev commented Mar 17, 2022

@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.

@CharlieDigital
Copy link

@mdddev one can dream!

@a3y3
Copy link

a3y3 commented Apr 18, 2022

Seems like this works already out of the box on Visual Studio? Not sure how the IDE does it under the hood but it has a hot reload button that applies the current changes in less than a second.

@bmind7
Copy link

bmind7 commented Aug 31, 2022

For JS restart: true added to launch.json saved my day
https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_restarting-debug-sessions-automatically-when-source-is-edited

@safwanmasarik
Copy link

Eureka. I solved it in an elegant way. Here code ref: https://github.com/safwanmasarik/Azure-Function-Typescript-Hot-Reload .
Video evidence:
https://user-images.githubusercontent.com/35250295/201973704-b11eeb4a-8d41-4e0b-9f9b-385fdcf10846.mp4

@iljaiwjew
Copy link

Any progress on this for TypeScript? It's very annoying that such basic feature doesn't work

@allprogrammers
Copy link

This feature is really needed

@Trubador
Copy link

Any update on this?
Development speed is very important.

@mdddev
Copy link

mdddev commented Aug 4, 2023

I second this. Out-of-the-box hot reload functionality is needed. Since this by the OP is a generic Hot Reload request generic with respect to the programming language used, there seem to be mainly two sides to this converstation. The ones using Javascript/Typescript and the ones using NET/C#. While there appear to be some workarounds for Typescript, none so far have presented themselves for NET.

I this something on the roadmap of the Azure Function Core Tools? Modern Azure Functions in the isolated worker are basically a console application, for which hot reload is supported, right? Therefore I assume it is in the way the Azure Function Core Tools choose to interact with the ability (or not).

@jaemsnrg
Copy link

If anyone was like me and ran into the looping nodemon issue, here is a fix:

package.json:
...
"start": "nodemon"
...

nodemon.json:
{
"watch": ["your_function_folder/"],
"ext": "js,json",
"ignore": ["node_modules/"],
"exec": "func start --verbose --javascript -p 3030 --watch"
}

@rafaelgrilli92
Copy link

Still not working for TypeScript. I can't believe a simple thing like this that speeds up the development process so much is still an issue.

@Crisfole
Copy link

If this isn't working for you in TS you should check your RUN_FROM_PACKAGE setting. It must be falsey (0 or unset) for picking up changes to your code as they come in.

@mdddev
Copy link

mdddev commented Nov 21, 2023

Raising the flag for .NET here again, as most of the posts here are for Typescript. allthough the thread started with C# 😊

As far as I can tell, all IDEs except (full blown) Visual Studio rely on the Function Core Tools to manage an Azure Functions project. I have had the same Hot Reload trauma with Jetbrains Rider as I had it with VS Code. It's just not working.

I don't know how VS does it, but it seems like it does not rely on the Function Core Tools.

Is it even considere to be on the roadmap anytime soon?

Another LTS version of NET has jsut dropped, and I am always super excited about the great tooling integration of NET. Everything is faster and better than ever before. Only working with Functions feels like a road bump without a Hot Reload functionality. I'm using it (hot reload) elsewhere and it is really hard to go back, once you realise how much more productive you are with it.

@subesokun
Copy link

subesokun commented Dec 7, 2023

I got this working with TS and the latest Azure Function Core Tools:

  • Initialize the VSCode project via > Azure Functions: Initialize Project for Use with VS Code...
  • Make sure that you've set sourceMap: true in your tsconfig.json compiler options (otherwise the breakpoints won't work)
  • Launch the debugger task Attach to Node Functions
  • Open a second terminal and run npm run watch (for hot reload)

With that you should be able to set breakpoints in your TS code and hot reload the function host on code changes.

@mdddev
Copy link

mdddev commented Dec 7, 2023

I'm glad you got this working. Although I do not understand why .NET's hot reload feature is not working with one of the supported .NET languages. I guess it might be time to abandon .NET and go with TS, since there is clearly no indication that there will be any improvements soon. Sad.

@danielniccoli
Copy link

danielniccoli commented Jan 10, 2024

Hot reloading works for me. I develop in Python with the V2 model. Have not tried any other language. When I change code, the running app takes a moment to reload and the next time I trigger a function, the updated code is used.

I noticed one thing, though. I develop in VS Code with the ms-azuretools.vscode-azurefunctions extension. It comes with some a pre-configured launch.json and tasks.json, so I just have to press F5 to start debugging. When debugging that way, hot reload does not work.

Instead, I start the host normally with func host start --language-worker -- "-m debugpy --listen 127.0.0.1:9091" and then use a custom debug config that attaches to the debugger without the shipped pre-launch tasks. Now when I change code, the function host does hot reload and I only have to re-attach the debugger.

I opened a ticket about this here: microsoft/vscode-azurefunctions#3936

@fernandorovai
Copy link

fernandorovai commented Feb 2, 2024

Any way to ignore files on the same project to avoid hot reloading in Python?

@LevYas
Copy link

LevYas commented Jul 16, 2024

In case anyone is interested, I've found a workaround.

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

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

Does this workaround still work on .NET 8 and in-process functions? I've just migrated to .NET 8, and func start works fine, but if I run dotnet watch -v msbuild /t:RunFunctions it fails to start:

dotnet watch ⌚ Running  with the following arguments: 'msbuild /t:RunFunctions'
dotnet watch ⌚ Error while killing process ' ': No process is associated with this object.
dotnet watch 🚀 Started
dotnet watch ❌ Application failed to start: Cannot start process because a file name has not been provided.
dotnet watch ⌚ Caught top-level exception from hot reload: System.InvalidOperationException: Cannot start process because a file name has not been provided.
   at System.Diagnostics.Process.Start()
   at Microsoft.DotNet.Watcher.Internal.ProcessRunner.RunAsync(ProcessSpec processSpec, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(DotNetWatchContext context, CancellationToken cancellationToken)

I tried to understand what is the process dotnet watch complains about, but no luck.

@SwenRanj
Copy link

We are also facing problems with our containerized Azure Functions app in TypeScript. Any ideas on how to enable auto reloading in Docker scenario?

Our scenario is based of the hello-world-tab-docker MS teams sample. The 'api' directory contains the actual Azure Functions app.

@MonkeyNinja
Copy link

We are also facing problems with our containerized Azure Functions app in TypeScript. Any ideas on how to enable auto reloading in Docker scenario?

Our scenario is based of the hello-world-tab-docker MS teams sample. The 'api' directory contains the actual Azure Functions app.

If you need to use Docker, then you have to copy the project files to the container, and not access it through the share. Shares do not propagate the file change notifications that hot reload requires to 'watch' sources and deps.

@SwenRanj
Copy link

SwenRanj commented Nov 6, 2024

We are also facing problems with our containerized Azure Functions app in TypeScript. Any ideas on how to enable auto reloading in Docker scenario?
Our scenario is based of the hello-world-tab-docker MS teams sample. The 'api' directory contains the actual Azure Functions app.

If you need to use Docker, then you have to copy the project files to the container, and not access it through the share. Shares do not propagate the file change notifications that hot reload requires to 'watch' sources and deps.

We use volumes to 'share' code file with the image. The issue for us was more in the command baked into the mcr.microsoft.com/azure-functions/node image. In the end, and this is probably not ideal, we solved it by watching the files and running the command baked in the image:

Node Script (package.json):
"dev:docker": "npx tsc-watch --onSuccess \"/opt/startup/start_nonappservice.sh\""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests