vue-cli创建vue2 uni-app项目步骤,及报错解决方案
1、安装vue-cli
npm install -g @vue/cli@4
官方提供命令是
npm install -g @vue/cli
安装的是版本5,但uni-cli仅支持vue-cli 4.x版本,启动会报错
2、使用vue-cli构建项目
vue create -p dcloudio/uni-preset-vue my-project
这个步骤会报如下错误:
ERROR Failed to get response from https://registry.npm.taobao.org/binary-mirror-config
yarn install v1.22.22
info No lockfile found.
[1/4] 🔍 Resolving packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Error: certificate has expired
at TLSSocket.onConnectSecure (_tls_wrap.js:1515:34)
at TLSSocket.emit (events.js:400:28)
at TLSSocket._finishInit (_tls_wrap.js:937:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:709:12)
ERROR command failed: yarn
这是因为淘宝镜像地址https://registry.npm.taobao.org
已经停用,需要更换为https://registry.npmmirror.com
而vue-cli4.x目前还是使用的旧地址,我们可以通过如下方式解决:
- 执行命令
npm root -g
查看全局安装目录 - 进入该目录,找到vue-cli的镜像配置文件
@vue/cli/lib/util/registries.js
,将文件内容替换为
const registries = {
npm: 'https://registry.npmjs.org',
yarn: 'https://registry.yarnpkg.com',
taobao: 'https://registry.npmmirror.com', // 主要是这段
pnpm: 'https://registry.npmjs.org'
}
module.exports = registries