50

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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Romain Rnd
  • 501
  • 1
  • 4
  • 7

19 Answers19

53

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 uninstall -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
    
vimuth
  • 5,064
  • 33
  • 79
  • 116
M A Azad
  • 539
  • 4
  • 3
10

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

10

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.

rvng
  • 156
  • 1
  • 7
  • Thanks, this is the right answer. The build mechanism of Angular is really strange - I never came across such issue with React. – Sailab Rahi May 03 '23 at 09:34
7

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
elmaystro
  • 117
  • 2
  • 7
4

reinstall node_modules

  1. git clean -dfx
  2. npm i

if persist, use yarn install first, then repeat above

elegentin
  • 289
  • 1
  • 4
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.

kiner_shah
  • 3,939
  • 7
  • 23
  • 37
2

Remove existing angular

npm uninstall -g @angular/cli

and Install

npm install -g @angular/cli --force

Adarsh K
  • 21
  • 1
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.

Meet Patel
  • 482
  • 4
  • 12
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!

Rydberg
  • 11
  • 3
0

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

jalil
  • 476
  • 1
  • 7
  • 16
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

Karl
  • 3,099
  • 3
  • 22
  • 24
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
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0
npm install --legacy-peer-deps
npm cache clean --force
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

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

  • 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](/help/how-to-answer). – Community Oct 11 '21 at 10:41
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.

  • Please check the [help center](https://stackoverflow.com/editing-help) for info on how to format code. – Tyler2P Dec 26 '21 at 15:55
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

ppenchev
  • 127
  • 1
  • 10
0

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

live-love
  • 48,840
  • 22
  • 240
  • 204
0

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

brew install angular-cli
0

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.

Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42