跳到主要内容

MacOS npm 网络访问疑难杂症

· 阅读需 1 分钟

镜像

npm一般需要通过镜像来访问,国内常见的镜像有:

推荐使用nrm管理要使用的镜像:

npm --registry https://registry.npmmirror.com install nrm
nrm use tencent

CA证书问题

在通过镜像使用npm install时,大概率会提示unable to get local issuer certificate,这需要配置好npm使用的CA证书。

安装必要CA证书:

brew install ca-certificates

设置npm使用的CA证书:

npm config set cafile /usr/local/share/ca-certificates/cacert.pem

其它问题

node-gyp需要本地机场的辅助访问,方式如下:

node-gyp install --proxy=<http://proxy_addr:port> --cafile=/usr/local/share/ca-certificates/cacert.pem