9

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

LazyOne
  • 158,824
  • 45
  • 388
  • 391

10 Answers10

10
  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 react-scripts@2.1.8
npm start

Also, make sure you have this entry in your PATH environment variable.

C:\Users\{user_name}\AppData\Roaming\npm

Dilshan
  • 2,797
  • 1
  • 8
  • 26
  • Try without create-react-app. Check this link https://medium.com/@paul.allies/react-create-app-without-react-create-app-7c8341282645 . If it is still not working, it should be a problem with nodeJS. Also, you can try React with CDNs. – Dilshan Apr 28 '19 at 07:38
  • Hey, I just noticed that you are a SLIIT student. I'm also a SLIIT. Are these stuffs in the syllabus? – Dilshan Apr 28 '19 at 07:39
  • Thank you! I'll check.. yes we do have them in the syllabus – Linisha Siriwardana Apr 28 '19 at 10:34
  • This will help to, https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows – Dilshan Apr 28 '19 at 15:03
  • oh, thank you so much. I tried almost everything but still couldn't find what's wrong. I will try what you said. thank :) – Linisha Siriwardana Apr 28 '19 at 17:22
  • Do you only try to npm start? is there any backend server or API running? Maybe sometimes you get this kind of error due to PORT is already in use. Run this command `netstat -an` , it will show all the running ports. Usually react app start at localhost:3000, Make sure you don't see this line after run above code. `TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING ` – Dilshan Apr 29 '19 at 13:11
  • I tried to run in a different server as well. there are no backend servers running – Linisha Siriwardana Apr 29 '19 at 13:59
  • Thank you so much! i will let you know if i find a solution. – Linisha Siriwardana Apr 29 '19 at 15:23
3

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.

devansh
  • 89
  • 2
  • 8
  • or also if you are on a Linux pc, you can destroy the background process, that's what happened to me (I had a systemd process running in the background): `systemctl stop daemon_name` – ego2509 Feb 05 '21 at 00:24
2

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.

spekulatius
  • 1,434
  • 14
  • 24
  • Hey @spekulatius, can you update this answer with details on how to resolve the issue? It's generally frowned upon to link directly to your own blog post without including the necessary details in the answer itself. – Chris Owens Jul 08 '21 at 23:12
1

Try to add C:\Windows\System32 to your Environment Variables Path.I had this issue using WSL and adding above resolved my problem.

VVN
  • 1,607
  • 2
  • 16
  • 25
0

Rebooting the System worked for me

Credit: Solution link

  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable in future. – Usama Abdulrehman Jul 05 '20 at 11:25
0

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.

enter image description here

0

I also faced this issue when I first started which I solved by running the command below for installing node-modules:

npm install --save react-scripts@2.1.8

Itchydon
  • 2,572
  • 6
  • 19
  • 33
Phean
  • 9
  • 1
  • 3
  • Can you explain further by editing your answer, what lead to you to this solution? That kind of context can be very helpful in others figuring out their own issue if it is slightly different. – Benjamin Charais Aug 06 '20 at 16:54
0

Check that you have the following under PATH System Variables

C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
Ian Gibblet
  • 552
  • 3
  • 18
0

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
0

Close Code Studio or sublime text or whatever editor you have your project open in