Search code examples
reactjsnpmenvironment-variablessystem-variable

npm start not working after changing PATH system environment variable


When i try to start my react application with npm start, i get the following error:

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

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
Starting the development server...

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

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADgAMAA4ADYALwBwAG8AcgB0AGEAbABgACIAIgA='
  ]
}

The command was executed in Visual Studio Code. Executing the command in a command shell produces nearly the same error:


> [email protected] start
> set PORT=8086 && set HTTPS=false && react-scripts start

i 「wds」: Project is running at http://172.19.42.69/
i 「wds」: webpack output is served from /portal
i 「wds」: Content not from webpack is served from C:\Users\...
i 「wds」: 404s will fallback to /portal/
Starting the development server...

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

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADgAMAA4ADYALwBwAG8AcgB0AGEAbABgACIAIgA='
  ]
}

Lately i had trouble with installing maven and accidently removed the PATH system environment variable. I kind of restored it somehow but maybe some things still don't work properly, which could be the reason for the error.

My PATH system environment variable:

%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
%USERPROFILE%\AppData\Local\Programs\Microsoft VS Code\bin
%MAVEN_HOME%\bin
C:\Windows
C:\Windows\System32\Wbem
C:\Program Files\nodejs\
C:\Program Files\Git\bin\
C:\Program Files\Git\cmd\
C:\Windows\System32

Update

npm start runs the following code: set PORT=8086 && set HTTPS=false && react-scripts start

NPM and node.js seem to work fine:

> node -v

v16.13.2

> npm -v

8.4.0

Solution

  • I found a solution to my problem.

    At first i copied the values of the PATH system environment variable from a friend:

    %USERPROFILE%\AppData\Local\Microsoft\WindowsApps
    %USERPROFILE%\AppData\Local\Programs\Microsoft VS Code\bin
    %MAVEN_HOME%\bin
    C:\Program Files\Git\bin\
    C:\Program Files\Git\cmd\
    %SystemRoot%\system32
    %SystemRoot%
    %SystemRoot%\System32\Wbem
    %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
    %SYSTEMROOT%\System32\OpenSSH
    C:\Program Files\nodejs\
    

    After that i got the following error for every npm command i tried to execute

    npm ERR! Unexpected token '.'
    

    So i followed this guide to completely remove node and then reinstalled the node lts version 14.19.0. After that everything worked fine again.