5

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.

NeNaD
  • 18,172
  • 8
  • 47
  • 89
  • Does [this](https://stackoverflow.com/questions/70045198/windows-script-host-error-invalid-character-code800a03f6-source-microsoft/70214942#70214942) solve your problem? – Dean Dec 24 '21 at 19:23

7 Answers7

1

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

Sercan
  • 4,739
  • 3
  • 17
  • 36
0

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.

Mahdi Zarei
  • 5,644
  • 7
  • 24
  • 54
  • Sorry, your answer is not that clear. Can you explain step-by-step what should be done? – NeNaD Dec 24 '21 at 11:30
  • I did what you said. Now I call `ng` command, but however I call it it always give the same result - it audits all possible options to call it (like I called `ng help`). – NeNaD Dec 24 '21 at 12:28
  • When you run .mkv files for the first time you have to choose a program to open those files. Like that, link a js file to be opened by node.js exe file. You can change the default for .js files in properties. – Mahdi Zarei Dec 24 '21 at 12:51
  • I did, and now I have the behavior from the comment above. Whatever I do, I always get `ng help` output. – NeNaD Dec 24 '21 at 13:19
0
  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"
minabagheri
  • 541
  • 2
  • 9
  • I have a lot of other CLI tools installed globally. If I would delete `npm` folder in `Roaming` folder, that would delete all others globally installed tools. – NeNaD Dec 26 '21 at 17:34
  • When this problem occurred to me and my problem was not solved by unistalling npm and unistalling Angular, I had to do this and my problem was solved If you do not find a way, do it eventually – minabagheri Dec 27 '21 at 05:50
0

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

0

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
Yashwanth Sai
  • 53
  • 1
  • 3
0

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.

dkrx81
  • 63
  • 1
  • 8
-1

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