Search code examples
powershellvisual-studio-codeterminal

ng server command opens file "open option menu"


When I use 'ng' in the Visual Studio terminal or PowerShell, the following window opens. I don't know how to solve it.

I cannot create components, schematics.

Every time 'ng' is called, the following window pops up:

What appears when I start NG

@mklement0 I tried reinstalling: Node.js PowerShell-7.2.3-win-x64

Problem solved, using :

Get-Command -Type Application ng |
Where-Object { $_.Source -match '\ng$' } |
Remove-Item


Solution

  • Note: The solution below applies analogously to npm - simply replace all occurrences of ng with npm in the command below.

    The implication is that in one of the directories listed in your $env:PATH environment variable there is an extension-less file literally named ng and that the same directory doesn't also contain an ng file with a filename extension that marks it as an executable, i.e. one of the extensions listed in $env:PATHEXT.

    While such a file isn't considered an executable file, PowerShell tries to open it as a document (which is essentially the same as double-clicking a document in File Explorer):

    • When extension-less documents are opened, they always pop up the GUI dialog shown in your question, because you cannot persistently associate an application with them.

    To solve your problem you need one to two steps:

    • Look for files literally named ng (no filename extension) in the directories listed in $env:PATH and remove them:

      # Note: This may require running from an ELEVATED session (as admin).
      #       IMPORTANT: 
      #         -WhatIf *previews* the deletion.
      #         Remove it, once the output shows the file(s) you want to remove.
      Get-Command -Type Application ng | 
        Where-Object { $_.Source -match '\\ng$' } | 
          Remove-Item -WhatIf
      
      • Through this deletion, a true ng executable (a file whose extension is one of the extensions listed in $env:PATHEXT, such as .exe or .cmd) may then surface, from another directory listed in $env:PATH, which the extension-less ng file may have shadowed.
    • If no such executable surfaces, you'll have to (re)install the desired ng application.