eas : The term 'eas' is not recognized as the name of a cmdlet, function, script file, or operable program - expo

930 views Asked by At

every thing was working fine with development build until I edited some user variables mistakenly .

then all eas commands end with this error:

eas : The term 'eas' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At line:1 char:1
+ eas login
+ ~~~
    + CategoryInfo          : ObjectNotFound: (eas:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I've tried npm install -g eas-cli and npm uninstall -g eas

and didn't work

2

There are 2 answers

0
mermaid On BEST ANSWER

I fixed it after adding these paths into system variables

1_ C:\Users\YourPcName\AppData\Roaming\npm and I moved it up to the top of all other paths

2_ C:\Users\YourPcName\AppData\Roaming\npm\node_modules\eas-cli\bin

0
mklement0 On

Your question boils down to how to repair the persistent definition of the PATH environment variable so that CLIs installed globally with npm install -g can again be invoked by name only, such as eas in your case.

To that end, make sure that the directory path output by npm prefix -g - normally "$env:APPDATA\npm" - is part of the user-level definition of the PATH environment variable in the registry.[1]

  • Note: You only need to add this one directory - it is where entry points (*.cmd and .ps1 files and Unix shell scripts) for all globally installed CLIs are placed.

To automate the process:

$globalClisDir = npm prefix -g

# Make sure the directory is listed in the *persistent, user-level* definition
# of the PATH env. var. in the registry.
if (([Environment]::GetEnvironmentVariable('Path', 'User') -split ';' -eq $globalClisDir).Count -eq 0) { 
  # Important: Get the current definition in *unexpanded* form directly
  #            from the registry.
  $userPathRaw = 
    (Get-Item HKCU:\Environment).GetValue('Path', $null, 'DoNotExpandEnvironmentNames')
  # Update it with the directory appended.
  Set-ItemProperty HKCU:\Environment Path "$userPathRaw;$globalClisDir" 
}

Note:

  • The updated PATH value will take effect in future PowerShell sessions, though you'll need to communicate to the Windows shell that environment variables have changed:

    • In the simplest form, force-restart all explorer.exe windows:

      Stop-Process -Name explorer
      
    • For a gentler approach, see the linked answer below.

  • To also update it for the current session, run:

      $env:PATH+=";$(npm prefix -g)"
    
  • The sole purpose of the if statement is to prevent accidentally adding the directory multiple times.

  • This answer explains why it is important to update Path - and other environment variables that are defined as REG_EXPAND_SZ registry values - directly via the registry, and not with utilities such as setx.exe or the [System.Environment]::SetEnvironmentVariable() .NET API.


[1] Since globally installed npm packages are placed in a user-specific location (which other users generally cannot access), it makes sense to only modify the user-level PATH definition.