Angular報錯-Error: ENOENT: no such file or directory, scandir '/Users/echo_hx/node_modules'

2019-11-07   更新

我知道爲啥報錯了,自我好好反省一下!!!

 

所以,Mac的終端,不能用簡寫的命令,哭泣。。。

不過下面的,就可以看作安裝卸載@angular/cli了


在全局安裝angular-cli且成功之後,查看ng v ,報錯了Error: ENOENT: no such file or directory, scandir '/Users/echo_hx/node_modules'。。。。

我去查了日誌,如下:

[error] Error: ENOENT: no such file or directory, scandir '/Users/echo_hx/node_modules'
    at Object.readdirSync (fs.js:854:3)
    at VersionCommand.run (/usr/local/lib/node_modules/@angular/cli/commands/version-impl.js:50:41)
    at VersionCommand.validateAndRun (/usr/local/lib/node_modules/@angular/cli/models/command.js:134:39)
    at async Object.runCommand (/usr/local/lib/node_modules/@angular/cli/models/command-runner.js:186:24)
    at async default_1 (/usr/local/lib/node_modules/@angular/cli/lib/cli/index.js:54:31)

我百度了,也沒找到實用的方法。它們總是node-sass安裝問題,頭禿。於是,我只能卸載重裝了,一般npm也會產生不可預料的未知錯誤,所以也要安裝cnpm,用yarn也行。

1.重裝angular-cli

npm uninstall -g @angular/cli

再清一下緩存

npm cache clean --force

若清空緩存時出現錯誤,執行以下命令,要麼沒權限啥的,用sudo 

npm cache clear --force && npm install --no-shrinkwrap --update-binary

2.設置淘寶代理,以安裝cnpm。cnpm可代替npm,命令格式相同。

npm config rm proxy
npm config rm https-proxy
sudo npm install cnpm -g --registry=https://registry.npm.taobao.org

3.然後安裝Angular-cli

cnpm install -g @angular/cli@latest

最後,ng v 查看版本

 

OK,,,完美……^ _ ^

參考文章:全局安裝 Angular CLI

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章