19

I run webpack-dev-server from windows console with the command:

webpack-dev-server --content-base ./build --inline --hot

after this I see message webpack: bundle is now VALID. and I can't type anything there. But if I change something in webpack.config.js I have to close console, open it again and start webpack-dev-server for apply my changes. How can I stop webpack dev server without close console?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rajab Shakirov
  • 7,265
  • 7
  • 28
  • 42
  • I think there needs to be a better answer for this question. I too have problems stopping the process. CTRL+C once or twice almost always results in orphaned processes and I have seen this happen both on the side of Windows and WSL. It also does not pick up on the CTRL+C in a way where it asks if I would like to terminate the process. It just acts like it was forcefully closed. – Joshua Dannemann Jul 08 '20 at 21:00

9 Answers9

33

You only need to type Ctrl+C two times

thitemple
  • 5,833
  • 4
  • 42
  • 67
  • 4
    I found that, for an unknown reason, `ctrl+c` wasn't being recognised (despite working elsewhere), but `ctrl+break` twice worked fine. – Richard Szalay Jun 02 '16 at 06:35
  • 23
    For some reason this server still runs for me, and is an orphaned process. – the_5imian Feb 20 '17 at 01:37
  • 2
    I run the devserver through npm using "npm start". When I kill npm with CTRL+C, I get the same problem... webpack devserver is still running in the background as an orphaned process. – Jason Slobotski Feb 22 '17 at 16:45
  • 1
    CTRL+BREAK works for me. Everything else just hung tight. – httpete Aug 04 '17 at 14:07
  • The docs for NPM's CLI run command: https://docs.npmjs.com/cli/run-script.html __ It simply says the shell that runs the script is platform dependent. I have been unable to confirm the orphaned process comment by either using ctrl+c or by closing the default Windows 10 console. Doing either terminates the batch job. ...console me if you wanna live – Ususipse Oct 14 '19 at 07:34
20

I run webpack devserver by issuing the "npm start" command. I've found that CTRL+C doesn't work for me and just creates an orphaned process. I'm able to kill the devserver by opening the task manager and killing any running node.exe processes.

Another way to do this from plain jane windows console is to find the node process Ids and kill them.

tasklist /FI "IMAGENAME eq node.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
node.exe                      4620 Console                    2     44,568 K
node.exe                     12452 Console                    2    486,260 K

Then kill them with the following command.

taskkill /F /PID 4620 /PID 12452

An alternative more direct approach as pointed out by a comment.

taskkill /F /IM node.exe
Jason Slobotski
  • 1,386
  • 14
  • 18
6

I have also been running into this hard-to-kill webpack-dev-server process on my Windows machine lately.

Ctrl+C/break and even closing were getting me nowhere and I quickly tired of manually tracking down the process and killing it.

This one-liner did the trick for me:

for /f "tokens=5" %a in ('netstat -aon ^| findstr 8080 ^| findstr LISTENING') do taskkill /pid %a /f

I went ahead and made a kill-server.bat file for it:

@echo off
for /f "tokens=5" %%a in ('netstat -aon ^| findstr %1 ^| findstr LISTENING') do taskkill /pid %%a /f && echo killed PID %%a

I put that on my PATH, so now to kill a server using a specific port I can just:

kill-server 8080

On a side note, this issue seems to happen for me only when I use console emulation tools, not when I am using the windows command prompt directly.

2

On Windows this Powershell seems to kill it (and all Node processes!)

get-process node | Stop-Process
Damien Sawyer
  • 5,323
  • 3
  • 44
  • 56
1

How can I stop webpack dev server without close console?

Go to Task-Manager and close the task Node.js: Server-side JavaScript.

fabpico
  • 2,628
  • 4
  • 26
  • 43
0

In my case it was enough to hit Ctrl+C once. After that, I get two prompts for terminating job: Terminate batch job (Y/N)? ^CTerminate batch job (Y/N)?

After confirming the first, a regular command prompt is shown. But I have to once again write hit "Y" and confirm, which confirms the second background job termination. Otherwise it stays orphaned.

Michal Filip
  • 870
  • 8
  • 9
0

There appears to be a bug on Git Bash not properly sending the signal to node correctly.

I created this bash script:

echo killing process on port $1

taskkill //PID `netstat -aon | grep $1 | grep -P '(?=LISTENING).*' -o -m1 | grep -P '\d*' -o` //F

Add add it to your PATH

run with kill.sh 8000 for example.

dwjohnston
  • 11,163
  • 32
  • 99
  • 194
0

In my case CTRL+C did close the process on terminal but when I restarted the server I used to get

Error: listen EADDRINUSE: address already in use :::*port*

Tried a lot of bash and powershell commands but nothing seemed to fit into an npm script.

So finally, I used node module kill-port and everytime killed the port before starting the devServer.

package.json
{
  ...
  "scripts": {
       ...,
       "serve": "npx kill-port 9000 && npm run devServer",
       "devServer": "webpack serve --open --port 9000"
   }
}
abhishek khandait
  • 1,990
  • 2
  • 15
  • 18
-1
  1. Type: Ctrl+C once.
  2. When prompt Terminate batch job (Y/N)? Type: y

Works for me. I've attached the screenshot Thanks! command line screenshot