ng server command opens file open option menu

Viewed 850

In VS code editor, ng serve command opening "How do you want to open this file?" dialog box in

enter image description here

3 Answers

The answer by Petr Freiberg helped get me to what I believe is a better solution. Instead of deleting files that may or may not actually be important for the system, we should update our PATH variables so that the "correct" command is found first.

In my situation, I had my npm paths in this order:

  1. C:\Users\Me\AppData\Roaming\npm\node_modules\@angular\cli\bin
  2. C:\Users\Me\AppData\Roaming\npm

I just switched the order so that C:\Users\Me\AppData\Roaming\npm came first.

The issue is that the terminal is finding the first "command match" which may just be a file, so that is why it is asking where you want to open it.

I did run the command Run Get-Command -All ng | ForEach-Object Path as Petr suggested, which called out the order issue I describe here.

I encountered a similar problem when executing a Docker command within Visual Studio Code. I also got a window asking "How do you want to open this file?". I think the problem is not in Visual Studio Code, but in PowerShell, which Visual Studio Code uses.

I solved it like this:

  • Run Get-Command -All docker | ForEach-Object Path
  • Among the file paths returned, remove those that do not end in *.exe (use Remove-Item):

![enter image description here

For ng it should be same.

Credits: https://stackoverflow.com/a/63981418/1816014

i have faced the same issue, while trying to run ng -v or ng --version, it pops open a Open option editor, which gives following ng.js text...

#!/usr/bin/env node
'use strict';
 
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
  process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
  // If an error happened above, use the most basic title.
  process.title = 'ng';
}
 
// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map((part) => Number(part));
if (version[0] % 2 === 1 && version[0] > 14) {
  // Allow new odd numbered releases with a warning (currently v15+)
  console.warn(
    'Node.js version ' +
      process.version +
      ' detected.\n' +
      'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
      ' For more information, please see https://nodejs.org/en/about/releases/.',
  );
 
  require('../lib/init');
} else if (
  version[0] < 12 ||
  version[0] === 13 ||
  (version[0] === 12 && version[1] < 14) ||
  (version[0] === 14 && version[1] < 15)
) {
  // Error and exit if less than 12.14 or 13.x or less than 14.15
  console.error(
    'Node.js version ' +
      process.version +
      ' detected.\n' +
      'The Angular CLI requires a minimum Node.js version of either v12.14 or v14.15.\n\n' +
      'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
  );
 
  process.exitCode = 3;
} else {
  require('../lib/init');
}
 
what is the error here, i tried uninstall clear cache and install but still same error....
Related