Why npm start is throwing events.js:187 throw er; // Unhandled 'error' event in my react project?

Viewed 25069

While starting the server for the first time just after the code checkout , my react js project is throwing error "events.js:187 throw er; // Unhandled 'error' event" . I have node 12.13.0 and npm 6.12.0 . Log file attached log file

events.js:187
      throw er; // Unhandled 'error' event
      ^



    Error: spawn cmd ENOENT
        at Process.ChildProcess._handle.onexit 
       (internal/child_process.js:264:19)
       at onErrorNT (internal/child_process.js:456:16)
       at processTicksAndRejections (internal/process/task_queues.js:80:21)
    Emitted 'error' event on ChildProcess instance at:
       at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
       at onErrorNT (internal/child_process.js:456:16)
       at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    errno: 'ENOENT',
    code: 'ENOENT',
    syscall: 'spawn cmd',
    path: 'cmd',
    spawnargs: [ '/c', 'start', '""', '/b', 'http://localhost:3000/' ]
}
15 Answers

If your system is windows, set your environment variable, add %SystemRoot%\system32 to your PATH I met this error yesterday,hope it works to you. Don't forget reboot you PC

Downgrading the react-script version from 3.0.1 to 2.1.8 worked for me. Follow the following commands in sequence:- npm install react-scripts@2.1.8 npm install npm start

Try this if none of the above answers solved u.. Go to My Computer>Properties>Advanced and in the environment variables Edit the PATH and add the following

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; C:\Program Files\nodejs;C:\Users{yourName}\AppData\Roaming\npm

Add 4 of them and restart your PC

You can use node Your_File_Name.js command to run from the localhost. To use npm start command, you need to use scripts array in your package.json file "scripts": { "start": "http://localhost:3000/" } If this is not helpful can you attach more details?

Try to execute export PATH=$PATH:/mnt/c/Windows/System32. Change the path /mnt/c/ to the path mounted on your wsl Windows (mount).

if it works, insert the path /mnt/c/Windows/System32 into the file /etc/environment.

here in my case this solution worked

I faces this issue while using the windows subsystem for Linux and solved it by adding C:\Windows\System32 to Environment Variables Path. Environment Variables can add as follow.

go to

control panel -> System and Security ->System -> Advanced System Settings.

From the appearing dialog box, select Environment Variables, and then under System Variables select the path and select edit and add C:\Windows\System32. Restart the machine.

Just in case this helps someone else, I started using react-scripts@4.0.3 from a version of create-react-app that didn't include it, and suddenly I got this error.

It turned out the hot reload websocket was attempting to make a connection from the browser to my dev server, but it failed and crashed the app.

I found the fix here: I added transportMode: "ws" to my webpackDevServer.config.js beneath hot: true, and it worked.

Make sure all the global & local packages that are being used in the scripts are installed, I've spent hours debugging an issue while deploying an application because webpack-cli & yarn wasn't installed globally & my project was trying to access it locally.

In your package.json file try lowering the version of "react-scripts" to "2.1.8":

"dependencies": { 
    "@testing-library/jest-dom": "^4.2.4",  
    "@testing-library/react": "^9.4.0",  
    "@testing-library/user-event": "^7.2.1",  
    "react": "^16.12.0",  
    "react-dom": "^16.12.0",  
    "react-scripts": "2.1.8"  
  },  

Above works for me.

If you are experiencing this error on ubuntu simply prepend "sudo" to the npm start command. That is sudo npm start

downgrading react-scripts to npm install react-scripts@2.1.8 works for me

in my case react-scripts was missing from the devDependencies adding it in devDependencies resolved it for me. Hope this helps

If downgrading react-scripts not working for you please follow below steps

  1. Search Edit the system environment variable and open it.
  2. Click on Environment Variables.
  3. Select Path in system variables section and click on Edit.
  4. Click on New and add this %SystemRoot%\system32
  5. Click on OK everywhere and restart the system.

Try adding the following environment variables to PATH. (System variables)

C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem

They should be there by default but mine were missing for someone reason. I added them and the problem disappeared.

Had the same problem in windows, deleting the node_modules and then a npm install fixed it for me.

Related