Cannot find module @angular\cli\bin\ng

旧城冷巷雨未停 提交于 2020-12-30 04:56:37

问题


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 Windowsd 10.

Thank you,


回答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
    



回答2:


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.




回答3:


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



回答4:


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.




回答5:


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




回答6:


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




回答7:


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 symbol like &,etc in your folder name.



来源:https://stackoverflow.com/questions/51726959/cannot-find-module-angular-cli-bin-ng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!