56

I'm getting into trouble with anngular-cli installation because it doesn't recognize the ng command in my git bash but it works in my cmd on Windows 7.

I looked for some issues on the web but I didn't really find a solution.

Here, the error :

   ng -v
   module.js:549
    throw err;
    ^

   Error: Cannot find module 'C:\Program 
   Files\Git\node_modules\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

This error happened the first time I used ng after installing Node and angular-cli globally.

I didn't get this error when I was working on my laptop on Windows 10.

1
  • 5
    Running this npm install -g @angular/cli in root directory (for ex. in c:\) removed this error for me. Commented Nov 27, 2018 at 8:24

21 Answers 21

57

Problem:

Error: Cannot find module '..\AppData\Roaming\npm\node_modules\angular-cli\bin\ng' angularJs

Solution:

  1. uninstall angular cli if you have already installed it

    npm remove -g @angular/cli
    
  2. Delete the C:\Users\Satish\AppData\Roaming\npm\node_modules\@angular folder if it still exists after the uninstall

  3. reinstall angular-cli globally

    npm install -g @angular/cli
    
Sign up to request clarification or add additional context in comments.

4 Comments

2.5 I also had to delete ng.ps1 located in the C:\users\<userid>\AppData\Roaming\npm folder.
3. or with a specific version if you aren't on latest e.g. npm install -g @angular/[email protected]
removing npm and npm-cache folders from AppData helped me.and then doing the above helped me.
i ended up in this problem by running npx npkill
14

First, uninstall the angular cli using

npm uninstall -g @angular/cli

Then delete the "NPM" and "Npm-cache" folder under "Roaming" folder.

Now again install the Angular cli using

npm install -g @angular/cli

1 Comment

This answer works for me, I has to delete npm folder under roaming
11

In my case, i fixed it simply just by renaming my project folder.

before : "d/Gdrive/Sem 6 & 7/[project name]" after : "d/Gdrive/Sem 67/[project name]"

So i guess u may not put special characters in your folder name.

1 Comment

Thanks, this is the right answer. The build mechanism of Angular is really strange - I never came across such issue with React.
8

It worked for me only by removing npm and npm-cache folders from AppData then running :

npm uninstall -g @angular/cli

Then running :

npm install -g @angular/cli

Comments

4

reinstall node_modules

  1. git clean -dfx
  2. npm i

if persist, use yarn install first, then repeat above

1 Comment

thx, solved my problem
3

Looks like a dependency was removed somewhere. I worked around this by:

For local angular-cli: npm install @angular-devkit/core --save-dev

For global angular-cli: npm install -g @angular-devkit/core

Edit: As discussed below, you should perhaps not use --save-dev here.

Comments

2

Remove existing angular

npm uninstall -g @angular/cli

and Install

npm install -g @angular/cli --force

3 Comments

This answer is already contained in the existing answers for solving the problem.
Reinstall without force maybe a got an error
@AdarshK thank you very much. All I needed to do was add a --force flag when installing Angular CLI. Your comment saved my mental health.
1

The git bash is installed in C:\Program Files\Git where you never find the node_module folder that's why this error occurred

When you hit ng command from CMD it will look node_module folder in C:\Users\uername\AppData\Roaming\npm\ - where npm install global dependency and eventually it finds node_modules folder.

Basically for windows try to run from cmd.

1 Comment

Thank you, this is exactly what it happened in my computer... I was able to run from CMD
1

In my case the problem is

npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\node_modules\@angular\cli\bin\ng.js
npm ERR! dest C:\Program Files\nodejs\ng
npm ERR! EEXIST: file already exists, cmd shim 'C:\Program Files\nodejs\node_modules\@angular\cli\bin\ng.js' -> 'C:\Program Files\nodejs\ng'
npm ERR! File exists: C:\Program Files\nodejs\ng
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<UserId>\AppData\Roaming\npm-cache\_logs\2022-01-03T20_13_43_709Z-debug.log

Solution:

  1. I use this comment of npm 5 line on the shell

    $ npm ERR! File exists: C:\Program Files\nodejs\ng

  2. Delete the file ng and run:

npm install -g @angular/cli

And Done!

1 Comment

Just running the command in terminal helped: npm install -g @angular/cli
1

In my case, I spent a lot of time debugging the issue, trying to understand if it was specific to the NPM version or Angular before I realized that it could be the old fashion issue with too long path when dealing with application development on Windows.


So simply, instead of having my application path:

D:\...\Angular\...\...\application-name

I've changed it to a shorter version, like:

D:\application-name

and it worked, finally.

Comments

1

I solved it this way:

  1. cd to the previous directory of node_modules in the error path
cd C:\Users\<your name>\AppData\Roaming\npm

2.working

npm config set prefix
npm i -g @angular/cli

Anyway, it's resolved

Comments

0

I faced the same problem but running npm install solved my problem.

Comments

0

I had this error in Angular Console starting with release 11. I was missing a locale cli. So

npm install @angular/cli

solved my problem

Comments

0

It might be an issue with the package installation. Sometimes the installation might brake due to network issues. Also the access permission affects the installation.

So, try to install the package by running command prompt (CMD) as Run as administrator.

Follow the steps to resolve the issue.

1.Run CMD as Run as administrator mode.

2.Uninstall angular cli.

npm uninstall -g @angular/cli

3.Remove npm package files from the appdata folder.

Open Run option by pressing Windows + R key. Then type %appdata% and press OK.

Open the npm folder from the Roaming folder that you got in the explorer.

Delete ng and ng.cmd files from the npm folder if exists.

Open node_modules folder from there and delete @angular and angular/cli folder if exists.

4.Reinstall the angular cli

npm install -g @angular/cli

Comments

0
npm install --legacy-peer-deps
npm cache clean --force

Comments

0

If the environment variable path is properly set , please run ng in an angular project otherwise it will keep showing that error

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

once you run npm uninstall -g @angular/cli, check if there is an error in the console, it is usually a message with red line says "err!", mine said that it was unable to delete a file , follow the path of the file and delete manually ,then run npm uninstall -g @angular/cli and npm uninstall @angular/cli, when it goes successfully , run npm install -g @angular/cli , that should fix it.

1 Comment

Please check the help center for info on how to format code.
0

If most suggested and obvious solution below do not work

npm uninstall -g @angular/cli
remove roaming -> npm
npm install -g @angular/cli

Try to upgrade Node.js version. This solved the problem in my case after severl hours of investigation

Comments

0

Try deleting the node_modules folder (not the AppData one), the one in your project folder, and try reinstalling angular again.

Comments

0

If you have MAC(Mackbook) pc use brew command because we can not install angular-cli from npm command

brew install angular-cli

Comments

0

please reinstall with --force parameter.

npm install -g @angular/cli --force

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.