現象
最近使用ionic native開發應用,使用了cordova-plugin-webserver插件。
官網文檔提供指令安裝,一切正常(實際不正常,開始沒發現)。
npm install cordova-plugin-webserver
npm install @ionic-native/web-server
ionic cap sync
實際編譯運作的時候發現開啟服務失敗,錯誤資訊是“plugin_not_installed”。
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLyMTOxETMwEjMzIDNwEjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
排查
後來反複操作發現,運作“ionic cap cync”指令的時候,沒有顯示“cordova-plugin-webserver”。檢視“node_modules”目錄發現“cordova-plugin-webserver”目錄裡面隻有個“package.json”,其他什麼都沒有。到此基本可以判斷安裝出了問題。
最後google發現解決方案(參考:https://github.com/bykof/cordova-plugin-webserver/issues/34)。
結論
原來這個插件根本沒有完全釋出到npm上,是以通過“npm install cordova-plugin-webserver”指令無法正常安裝。解決辦法是直接通過github位址安裝。
ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver.git
或者
npm i https://github.com/bykof/cordova-plugin-webserver.git
參考資料:plugin_not_installed on android #34·bykof/cordova-plugin-webserver