1、安装webpack相关命令:npm install webpack -g;npm install webpack-cli -g
2、安装vue脚手架:npm install -g @vue/cli;或者yarn global add @vue/cli
3、安装vue项目:vue create test
4、跑项目:npm run serve;或者yarn serve
具体遇到的坑如下:
1、全局安装webpack,执行命令npm install webpack -g
全局安装webpack-cli,执行命令npm install webpack-cli -g
使用查看webpack版本的命令webpack -v(小写)
使用npm报错
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Program Files\nodejs\node_cache\_cacache\tmp\fc971ce3
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache\_cacache\tmp\fc971ce3'
npm ERR! [OperationalError: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache\_cacache\tmp\fc971ce3'] {
npm ERR! cause: [Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache\_cacache\tmp\fc971ce3'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\fc971ce3'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\fc971ce3'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
解决方案参考:https://www.cnblogs.com/qdjl/p/9481720.html
删除在C:\Users\{账户}\下的.npmrc文件
webpack -v报错
webpack : 无法加载文件 C:\Users\lx\AppData\Roaming\npm\webpack.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=13517
0 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ webpack -v
+ ~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
解决方案参考:https://blog.csdn.net/weixin_46449470/article/details/107583652
以管理员身份运行vs code
执行命令:get ExecutionPolicy,显示Restricted,表示状态是禁止的
执行命令:set ExecutionPolicy RemoteSigned
再执行命令:get ExecutionPolicy,就显示RemoteSigned
2、全局安装vue-cli3.0对应的新命令:npm install -g @vue/cli 或 yarn global add @vue/cli
yarn与npm对比参考:https://blog.csdn.net/qq_27674439/article/details/93976115
查看vue-cli3.0版本号:vue -version(小写),或者vue -V(大写)