Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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

like image 329
Linisha Siriwardana Avatar asked Apr 27 '19 13:04

Linisha Siriwardana


2 Answers

  1. Check your node version. update node & npm
  2. Try sudo npm start if you are in macOS or linux
  3. Try to download create-react-app again npm i -g create-react-app
  4. Try to create the app in another folder create-react-app APPNAME
  5. Still not working? Then delete node_module folder, package-lock.json and run npm install
  6. Try to run on another PORT
  7. Try with yarn. Install Yarn globally then run create-react-app myapp again. This time it will use yarn. try to start dev server with yarn start instead of npm 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

like image 189
Dilshan Avatar answered Nov 09 '22 05:11

Dilshan


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.

like image 3
devansh Avatar answered Nov 09 '22 03:11

devansh