Mac下安裝項(xiàng)目依賴(lài)包怯晕,報(bào)以下錯(cuò)誤:
在github上找到了Bug Report or Feature Request (mark with an x) 毒姨,是在angular/cli項(xiàng)目中提的issue惊奇, @filipesilva在該問(wèn)題下的回答:
This seems to be a problem with installing https://github.com/sass/node-sass, which is one of the dependencies.
The problem most likely arises from the use ofsudo
, which is heavily discouraged while installing packages. Check out https://docs.npmjs.com/getting-started/fixing-npm-permissions to see how you can fix your permissions.
fixing-npm-permissions 這個(gè)鏈接中給出了兩種解決方案:
1. Reinstall with a Node Version Manager (使用node版本管理器重新安裝node牲芋,比如nvm)
a. 先卸載之前安裝的node/npm (mac下需要使用sudo)
sudo rm -rf /usr/local/lib/node_modules # 刪除全局 node_modules 目錄
sudo rm /usr/local/bin/node # 刪除 node
cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm # 刪除全局 node 模塊注冊(cè)的軟鏈
b. 安裝nvm (適用于mac)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
詳見(jiàn):[https://github.com/creationix/nvm/blob/master/README.md]
安裝完 nvm 后耍共,輸入nvm乃沙,當(dāng)看到有輸出時(shí),則 nvm 安裝成功唉锌。若沒(méi)安裝成功隅肥,則需要做以下操作:
vi .bash_profile
然后將以下代碼復(fù)制進(jìn)去,保存退出
export NVM_DIR="$HOME/.nvm"
export NVM_NODEJS_ORG_MIRROR="http://npm.taobao.org/mirrors/node"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
然后 source 一下 .bash_profile
source .bash_profile
c. 使用nvm安裝node
nvm install 8.9.1 # 安裝 node8.9.1
2. Change npm's Default Directory (變更已安裝的npm的默認(rèn)目錄)
a. Back-up your computer before you start.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
??本系列文章只是簡(jiǎn)單記錄袄简,提供解決問(wèn)題的思路腥放,不保證其中所有步驟都可以如預(yù)期般有效!
作者使用第一種方案绿语,安裝nvm node管理器重新安裝node秃症,解決了此問(wèn)題。