Angular CLI v13 - Can not run "ng" commands

Viewed 2031

I upgraded Angular CLI to v13 globally, and when I try to use ng command it gives me this error:

enter image description here

I saw here that Angular v13 is compatible with Node v16.10.x so I installed Node v16.10.0 and it does not work again.

I perform standard operations:

npm uninstall -g @angular/cli
npm install -g @angular/cli@latest

I even try to clear npm cache and it still didn't work.

When I downgrade it and install Angular CLI v12 globally, everything works again.

Is this some known Angular CLI v13 issue?

Environment:

Windows 10 (win32 x64)

Update:

As a lot of answers suggested, I changed Windows Scripting Host to Node.js to run the .js files. Now ng command is executed, BUT whatever command I type, it always give me ng help output with all Available Commands. It's like all commands are mapped to ng help command.

7 Answers

I hope this solution works for you:

  1. Remove the user environment variable: C:\Users\AppData\Roaming\npm\node_modules@angular\cli\bin

  2. Uninstall angular

  3. Uninstall nodejs

  4. Reboot your pc

  5. Reinstall nodejs & angular

On Windows .js files are associated to Windows Scripting Host by default, so the script will not be run with Node. You can open explorer and find a .js file, you can check that it's not considered JavaScript.

Open a JavaScript file's properties and in the associated programs (or open with), link the node.js exe file to open that kind of files.

  1. Use the following command to delete your version

npm uninstall -g @angular/cli

  1. Unistall the node file with the following command

npm uninstall

  1. Go to your computer's file explorer Enter drive C. In the "search This PC" section, search for the word "App Data" and then "Roaming" Delete your "npm" file in the "Roaming" folder
  2. Enter the "npm install" command again
  3. Now it's time to enter the command "npm install -g @ angular / cli"

I don't really know if this is going to solve your problem, bit I'm going to suggest you an alternative solution, a different approach, which is the one I used when having different projects, I had problems with having a single version of node installed on my computer: TO USE A NODE MANAGER

I would recomend you Volta, a hassle-free way to manage your JavaScript command-line tool.

Just download its installable from here: https://github.com/volta-cli/volta/releases/download/v1.0.5/volta-1.0.5-windows-x86_64.msi and run it (with administrator permissions) to install it.

Once you have it installed, just run: volta install node@16 (or use another particular version of Node) It will install a new version of node, but "in a different way", although it will be transparent to you:

Volta does not use any fancy OS features or shell-specific hooks. It’s built on the simple, proven approach of shims. Whenever you install a tool with Volta, it adds a shim to your PATH that acts as an intelligent (and fast) router to the right version of the tool and runs it with the right Node engine. Volta is easy to install, with no external dependencies, because it’s built in Rust as a single, fast native executable.

https://docs.volta.sh/guide/getting-started

Change your default .JS files opener to node which is present in "C:\Program Files\nodejs". That's the only problem over there.

  1. Right click on any .js file and click on properties
  2. Now change opens with with Node present in this location: ""C:\Program Files\nodejs\node"
  3. Now your angular will execute properly in the cmd

Playing with different node.js versions/angular versions can screw up the npm folders (sub)structure leading to ng command fails to start.

The built in windows remove/unintall program procedure for Node will NOT remove the npm folder C:\Users\\{user}\AppData\Roaming\npm.

Remove this folder manually after node uninstall.

A downloaded (windows) Node installer installs a compatible npm as well, so these folders must be purged before a node reinstall - in my case i had to do it manually and ng started to work again.

I think you need to change ng.js file encoding format bom + utf8 to utf8

Related