AshtonMc
AshtonMc

Reputation: 37

Running yarn start on Windows 10 keeps failing

I am moving a web project from my Mac to a Windows 10 PC. I used Github Desktop to download all of files and I'm using Visual Studio Code to work on my project. Everytime I run both npm start or yarn start I get this error. I have tried deleting yarn.lock,package-lock.json, node_modules, using other script terminals, clearing my cache, npm install npm rebuild, yarn install. Everything I could find didn't work and I have no clue what to do. Any help would be appreciated. Thanks!

Here is the error message:

Starting the development server...

events.js:200
      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:81: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:81:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn cmd',
  path: 'cmd',
  spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Upvotes: 1

Views: 2476

Answers (1)

Syed Mishar Newaz
Syed Mishar Newaz

Reputation: 567

All right, look carefully at this:

{
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn cmd',
  path: 'cmd',
  spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}

  1. errno: 'ENOENT' means the file or directory is not found
  2. path: 'cmd' denotes the executable cmd was not found locally or globally while spawning process cmd via Node.js
  3. Now, I don't want to go into details. Just know that your operating system needs to keep track of some variables which can be accessed globally. One of such variable is called $PATH. The executables inside directories mentioned in the $PATH can be accessed from anywhere on your system.
  4. Here, 'C:\Windows\system32' is a path where windows keeps some critical executables. cmd.exe is one of them. Somehow the path was deleted from the $PATH variable. In order to fix the problem, an easy solution is:
    • Go to start-menu -> search and type environment variables and open it
    • There will be a variable named PATH. Append C:\Windows\system32 to it and press OK. If you're on Windows 7 or below, add a semi-colon ; before it
    • Restart your terminal or IDE or code editor and try running the app. See if the error comes again

Upvotes: 1

Related Questions