'Cannot find module @angular\cli\bin\ng

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.



Solution 1:[1]

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
    

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

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.

Solution 6:[6]

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.

Solution 7:[7]

Remove existing angular

npm uninstall -g @angular/cli

and Install

npm install -g @angular/cli --force

Solution 8:[8]

reinstall node_modules

  1. git clean -dfx
  2. npm i

if persist, use yarn install first, then repeat above

Solution 9:[9]

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!

Solution 10:[10]

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

Solution 11:[11]

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

Solution 12:[12]

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

Solution 13:[13]

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

Solution 14:[14]

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

Solution 15:[15]

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.

Solution 16:[16]

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