在ionic2項目的建立過程中,遇到了不少問題,前前後後花了不少時間才解決。
在網上查到,可能是npm的版本問題,但是也隻是可能。是以我就先照着簡單的方法做了。比如,直接跳過npm這個步驟。
使用指令行建立ionic項目
ionic start --v2 myApp tabs
我第一次遇到了這樣的錯誤
Installing npm packages...
Error with start undefined Error Initializing app: There was an error with the spawned command: npminstall There was an error with the spawned command: npminstall
天知道發生了什麼。後來重新建立的時候遇到了更可怕的錯誤。
Unable to run exec commandError: Command failed: npm install
npm WARN prefer global [email protected] should be installed with -g
Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.0/win3 2-x64-48_binding.node":
ESOCKETTIMEDOUT
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli 'G:\\myionicapp\\myApp\\node_modules\\node-gyp\\bin\\node-gyp.js' ,
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
...此處省略幾十行
就算我知道某個地方有錯,我也不敢保證以我的水準能夠handle它。本來我就是個小白。
于是在網上搜到有說,“在執行npm後無法通路國外資源庫。是以我們的操作是隻建立項目不建立依賴”。
執行這樣的指令。
ionic start --v2 myApp --skip-npm
然後再cd進myApp目錄,執行以下指令:
cnpm install --save
嗯。的确可以執行ionic serve。
結果執行ionic serve之後,網頁打開顯示 Error: ENOENT: no such file or directory, open 'g:\myionicapp\myApp\www\index.html'
WHAT HAPPENED???
後來又在網上搜到,說,這個bug在beta22已經修複,是以感覺是ionic的問題,是以npm stall -g ionic,安裝後版本為2.2.1,再start項目,然後ionic serve正常,www檔案夾下的檔案也全了。
更新之後終于能夠正常運作(看起來正常)。
參考資料:http://www.cnblogs.com/momoxiaoqing/p/6226706.html (這個小姐姐的部落格寫得很詳細,包括了ionic1和ionic2 剛開始建立所能遇到的大部分問題,并且解決方法親測可行)