ANY ng command will fail when trying angular due to invalid character error in ng file

Viewed 5580

The \AppData\Roaming\npm\node_modules@angular\cli\bin\ng.js file cannot be opened and it gives an error whenever I try to use an ng command anywhere, be it in an angular project or elsewhere.

The error is as follows: Script: (my username)\AppData\Roaming\npm\node_modules@angular\cli\bin\ng.js Line: 1 Character: 1 Error: Invalid Character Code: 800A03F6 Source: Compilationerror Microsoft Jscript

What I have tried:

using ng commands in different project -- same error reinstall npm, angular, removing the node modules in all combinations Setting the angular path in the environment variables

What happened before: ng command was missing possibly due to stuff related to python install. This error is replaced with my current problem when reinstall is done.

I have reinstalled everything to the fullest extent but the problem keeps persisting. I can use my angular project by running 'npm run ng serve' and that weirdly works.

Does anyone have ANY idea what might cause this problem

EDIT: I have somehow managed to resolve the problem but I have no clear answer what was the cause of it all. I did reinstall nodeJS on my computer which MIGHT have been broken during another project.

4 Answers

Remove the user environment variable

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

It worked for me after losing a day of life looking for a solution

Deleting and reinstalling node.js did not fix it. The issues started when I installed latest CLI which is 13.

I removed npm folder from C:\Users\username\AppData\Roaming then I installed the previous version

npm install -g @angular/cli@12.0.0

I do not get the error anymore.

In my case this error occured because of permissions on windows. Try to run cmd as Administrator.

Firstly you need to set the path of npm

$ npm config get prefix

make sure path matches with npm config get prefix

export PATH=/usr/local/share/npm/bin:$PATH

in windows you can set by advance system settings -> Environment variable -> set path.

Restart you system then do this -

$ npm install -g @angular/cli@latest

get package version

$ ng version

create workspace

$ ng new my-project

run the application

$ cd my-project

$ ng serve

Related