Saturday, September 18, 2021

“Port 4200 is already in use” - How to Kill Port in Windows

Angular Error - Port 4200 is already in use

Port 4200 is already in use. Use '--port' to specify a different port.
Error: Port 4200 is already in use. Use '--port' to specify a different port.
    at Server.<anonymous> (D:\Nagasai.Works\mobility-ui\node_modules\@angular-devkit\build-angular\src\angular-cli-files\utilities\check-port.js:27:28)
    at Object.onceWrapper (events.js:421:26)
    at Server.emit (events.js:314:20)
    at emitErrorNT (net.js:1343:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

This is what I used to kill the progress on port 4200

Windows users:

Port number 4200 is already in use. Open the cmd as administrator. Type below command after Opening your cmd.exe as administrator to list all active connections running under each local address  with Protocol and  Port number

netstat -a -n -o

Now find port with port number 4200 by right click on terminal and click find, enter 4200 in "find what" and click "find next": Let say you found that port number 4200 is used by pid 79016. Type below command in cmd

taskkill -f /pid 79016

How to fix Error: cannot find module "webpack"

Error on console regarding cannot find module "webpack"

Cannot find module 'webpack'
Require stack:
- D:\Nagasai.Works\vMobile-UI\node_modules\@angular-devkit\build-webpack\src\webpack\index.js

The Cannot find module webpack occurs when webpack is not globally installed. It is a problem with the npm script or application

Here is how we can fix

1. Install webpack in the local app folder

Ensure that you have installed the latest version of the webpack by running:
npm install webpack

2. Link webpack to your project

If the above solution does not work, try linking a globally installed webpack to your project. In your project, open the terminal, and type

npm link webpack