1. 使用国内源
# 用--verbose能打印出debug级的信息
npm install --verbose
# 查询当前使用的镜像源
npm get registry
# 设置为淘宝镜像源
npm config set registry https://registry.npmmirror.com/
# 还原为官方镜像源
npm config set registry https://registry.npmjs.org/
2. 跳过镜像源https证书过期错误
错误信息
14 http fetch GET registry.npm.taobao.org/create-vue attempt 2 failed with CERT_HAS_EXPIRED
解决
npm config set strict-ssl false
3. 解决与openssl兼容性问题
错误信息
Error: error:0308010C:digital envelope routines::unsupported
解决办法:
"scripts": {
"serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
"lint": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint"
}