6

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/' ]
}
Priyam
  • 153
  • 1
  • 1
  • 12

16 Answers16

4

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

2

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

Suprabhat Kumar
  • 645
  • 7
  • 13
Priyam
  • 153
  • 1
  • 1
  • 12
2

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

NeERAJ TK
  • 2,447
  • 1
  • 11
  • 25
1

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?

1

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

dmigo
  • 2,849
  • 4
  • 41
  • 62
1

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.

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

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.

Donnie C
  • 659
  • 1
  • 6
  • 9
0

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.

Creeptosis
  • 176
  • 1
  • 4
0

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.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Md Yeasin Arafat
  • 2,683
  • 1
  • 10
  • 5
0

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

Marvelous Ikechi
  • 2,031
  • 2
  • 15
  • 26
0

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

codemon
  • 11
  • 1
    It would be helpful to share context on why this solution would work. Also, "X works for me" is probably not the right level of confidence for an answer. – rahul Jun 12 '20 at 19:13
0

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

Ahmed J.
  • 484
  • 6
  • 11
0

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.
0

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.

Ian Gibblet
  • 552
  • 3
  • 18
0

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

0

In my case upgrading the Node.js to the latest LTS version (18.13.0) fixed the issue on my Windows 10 machine.

Wasid Hossain
  • 55
  • 1
  • 11