18

I'm having an issue with Powershell and CMD. When I try to execute Angular CLI commands in CMD like ng --version or ng new projectName, I get this error;

Windows Script Host Error: Invalid character

Code: 800A03F6

Source: Microsoft JScript compilation error

img1

MonoWolfChrome
  • 218
  • 2
  • 15
BAKHALED Ibrahim
  • 473
  • 1
  • 7
  • 19

8 Answers8

36

Update:

On Windows .js files are associated to Windows Scripting Host by default, so the script will not be run with Node.

Open a file explorer and find a JavaScript file, open the JavaScript file's properties and then "open with", select the Node.js program file to open that kind of files.

The error should stop after doing this.

Phil
  • 371
  • 2
  • 3
  • Finally something clear. Coalleagues were trying to install node, nvm, npm and ng-cli everytime when it hapens. Eventually it worked by doing so, but in the case it didn't, they were wondering "should I have install node or npm first?" – zameb Jul 11 '22 at 18:22
20

This is how I solved it: (on windows 10)

Go to C:\Users\<your_username>\AppData\Roaming\npm\node_modules\@angular\cli\bin

Check for ng.js

Right click on ng.js file and click on "properties" option

You need to open it with node.exe so click on "Change" button go to node js installed directory and

(example: C:\Program Files\nodejs\node.exe)

Select node.exe

Click on OK

It should change the color of ng.js like below:

enter image description here

Now try ng -v and other ng commands

J.K.A.
  • 7,272
  • 25
  • 94
  • 163
1

Installing this exact Angular version:

npm -g install @angular/cli@10.3.1

instead of the latest version:

npm -g install @angular/cli

fixed the above error.

Mike
  • 1,080
  • 1
  • 9
  • 25
hrimar
  • 11
  • 2
0

I ran into this exact issue after updating to Angular CLI 13. Tried tons of different suggestions from other threads. What is described in the solutions here is essentially what worked for me, but I just want to point out a possible alternative method to applying the fix that doesn't associate all JS files with node.js.

Trying to execute a script from package.json on Windows throws a JScript error

In your windows system environment variables is one variable called PATHEXT. If the value contains .JS;, remove it. Then restart your CMD windows.

0

make sure you have proper path variable configured as shown below

Go to your system variable settings

path variable snapshot

make sure you have all these mentioned as part of path C:\Users<userfolder>\AppData\Roaming\npm\node_modules@angular\cli C:\Users<userfolder>\AppData\Roaming\npm C:\Program Files\nodejs

0

make sure you have all these mentioned as part of path C:\Users\AppData\Roaming\npm\node_modules@angular\cli C:\Users\AppData\Roaming\npm C:\Program Files\nodejs

in my case, before npm install -g @angular/cli, the path of my system variable was:

C:\Users\AppData\Roaming\npm\node_modules@angular\cli\bin

I remove \bin and work!!!!!

0

Remember to fix this for the correct User

Associating .JS files to node.exe is the way to solve this.

BUT after struggling with the same issue, I wanted to add that the file association needs to be done with the same USER that you are working with the Terminal/Shell.

So if you use the Terminal as a Admin, you must login with your Admin Account just to fix the file association.

Cheers

0

(2023 - Latest): I got a similar Error. Go to the file by copying that path right click -> open with -> (by default its set to window script host) click(change)->select node (if u cant find node option)=> Install Node and open it by search an app in pc reference img and open with the node

u can see the icons will change js file to node now it will work fine!!