'How can I fix ('throw er; // Unhandled 'error' event') code lifecycle?
I tried to create a React app. I used the command prompt but after the app was created when I tried to start the npm it gives me some errors.
I tried to create React apps in WebStorm, IntelliJ and Visual Studio Code / PowerShell as well but still gives the same set of errors.
This is the error I get:
I tried many things like cleaning the npm cache, reinstalling npm and node, upgrading npm to new versions, tried to upgrade react but nothing worked.
events.js:173
throw er; // Unhandled 'error' event
npm ERR! code ELIFECYCLE
npm ERR! errno 1
gives some errors :
events.js:173
throw er; // Unhandled 'error' event
^
but it should start the npm and giving the localhost 3000
Solution 1:[1]
- Check your node version. update node & npm
- Try
sudo npm startif you are in macOS or linux - Try to download create-react-app again
npm i -g create-react-app - Try to create the app in another folder
create-react-app APPNAME - Still not working? Then delete
node_modulefolder,package-lock.jsonand runnpm install - Try to run on another PORT
- Try with
yarn. InstallYarnglobally then runcreate-react-app myappagain. This time it will use yarn. try to start dev server withyarn startinstead ofnpm start.
UPDATE
Also there can be have a problem with react-script version. You can try to downgrade the react script,
create-react-app my-app
cd my-app
npm install [email protected]
npm start
Also, make sure you have this entry in your PATH environment variable.
C:\Users\{user_name}\AppData\Roaming\npm
Solution 2:[2]
You have initialized the port twice. check your code .its code duplication.
app.listen(3000,function(){
console.log('we are on');
});
this has been written twice.
Solution 3:[3]
I've had the same issue (with a different framework & environment) frequently. I spend some time researching this and found a solution that worked for:
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
This removed all packages, the lock file and reinstalls everything. I've later found out that stopping addition watch process helps as well.
As this wasn't simply resolved for good I decided to write a blog post about it. It might be useful for your case as well.
Solution 4:[4]
Try to add C:\Windows\System32 to your Environment Variables Path.I had this issue using WSL and adding above resolved my problem.
Solution 5:[5]
Rebooting the System worked for me
Credit: Solution link
Solution 6:[6]
I faced this issue for almost half day, and finally response from @devansh gave me a hint to check for the port, somehow came to know that netstat is required to check the processId running on particular port, found out cmd was returning 'netstat' is not recognized while executing netstat command.
Anyways, long story short, simply adding System32 in environment path variable helped me resolve the issue.
Solution 7:[7]
I also faced this issue when I first started which I solved by running the command below for installing node-modules:
npm install --save [email protected]
Solution 8:[8]
Check that you have the following under PATH System Variables
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
Solution 9:[9]
I had the same error. Then i Check my node version and update node & npm. But the error is still there. So then I changed PORT. Now the error has gone.
Solution 10:[10]
Close Code Studio or sublime text or whatever editor you have your project open in
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow

