➜ ~ vue init webpack frontend
⠋ downloading template
/usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:313
throw er
^
Error: EACCES: permission denied, unlink '/Users/zhouqiang/.vue-templates/webpack/.gitignore'
at Object.unlinkSync (fs.js:974:3)
at rimrafSync (/usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:306:17)
at /usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:342:5
at Array.forEach (<anonymous>)
at rmkidsSync (/usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:341:26)
at rmdirSync (/usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:334:7)
at rimrafSync (/usr/local/lib/node_modules/vue-cli/node_modules/rimraf/rimraf.js:304:9)
at downloadAndGenerate (/usr/local/lib/node_modules/vue-cli/bin/vue-init:149:20)
at checkVersion (/usr/local/lib/node_modules/vue-cli/bin/vue-init:130:11)
at Request.request [as _callback] (/usr/local/lib/node_modules/vue-cli/lib/check-version.js:29:5)
at Request.self.callback (/usr/local/lib/node_modules/vue-cli/node_modules/request/request.js:185:22)
at Request.emit (events.js:189:13)
at Request.<anonymous> (/usr/local/lib/node_modules/vue-cli/node_modules/request/request.js:1161:10)
at Request.emit (events.js:189:13)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/vue-cli/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:277:13)
错误分析
这个问题其实也是比较简单的。直观的报错是在rimraf.js的313行抛出了异常。探究出现这个问题的原因要先知道rimraf.js的作用。它在做包的深删除时其实使用了Unix系统的rm -rf命令。而rm -rf是需要相应的权限才能够操作。
错误解决
运行vue命令时加sudo
sudo vue init webpack
这个问题的解决虽然很简单但是相信很多人会遇到,使用windows系统当然不会出现权限的问题。