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(大寫)