diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index af05fc6d4..6750a1620 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -379,6 +379,13 @@ func runFrontendDevWatcherCommand(cwd string, devCommand string, wg *sync.WaitGr cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout cmd.Dir = dir + + // not sure if this conditional is necessary, I mainly used it to prevent any issues with Windows + // since I do not have a Windows dev environment at the moment + // this conditional could be removed if found it causes no conflicts with Windows + if runtime.GOOS != "windows" { + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + } go func(ctx context.Context, devCommand string, cwd string, wg *sync.WaitGroup) { err := cmd.Run() if err != nil { @@ -406,6 +413,19 @@ func runFrontendDevWatcherCommand(cwd string, devCommand string, wg *sync.WaitGr } } } else { + // Experiencing the same issue on macOS BigSur + // I'm using Vite, but I would imagine this could be an issue with Node (npm) in general + // Also, after several edit/rebuild cycles any abnormal shutdown (crash or CTRL-C) may still leave Node running + // Credit: https://stackoverflow.com/a/29552044/14764450 (same page as the Windows solution above) + // Not tested on *nix + pgid, err := syscall.Getpgid(cmd.Process.Pid) + if err == nil { + err := syscall.Kill(-pgid, 15) // note the minus sign + if err != nil { + LogRed("Error from '%s' when attempting to kill the process: %s", devCommand, err.Error()) + } + } + LogGreen("Dev command killed!") cancel() } wg.Wait()