[Cordova] 增加 ios platform 時,出現 Failed to fetch platform cordova-ios 的問題

[Cordova] 增加 ios platform 時,出現 Failed to fetch platform cordova-ios 的問題

今天想用 Cordova 編譯出給 iOS 用的 app,

用 cordova platform add ios 指令,結果遇到了錯誤:

testuser@localhost ~ $ cordova platform add ios

Using cordova-fetch for cordova-ios@^4.4.0
Error: Failed to fetch platform cordova-ios@^4.4.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: npm: Command failed with exit code 254 Error output:
npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "cordova-ios@^4.4.0" "--save"
npm ERR! node v6.2.1
npm ERR! npm  v3.9.3
npm ERR! path /Users/testuser/node_modules/.staging/xml-escape-d3143b78
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/Users/testuser/node_modules/.staging/xml-escape-d3143b78' -> '/Users/testuser/node_modules/cordova-ios/node_modules/xml-escape'
npm ERR! enoent ENOENT: no such file or directory, rename '/Users/testuser/node_modules/.staging/xml-escape-d3143b78' -> '/Users/testuser/node_modules/cordova-ios/node_modules/xml-escape'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:

 

嗯… 看起來很詭異的錯誤…

我不知道這個 node_modules/.staging 是什麼東西,

試著用 npm 裝了 xml-escape 這個模組無效,

把裝好的 xml-escape 從 node_modules/xml-escape,

移到 node_modules/.staging 目錄下也無效…

 

上網查了一下,又試了以下幾個方法,全都無效:

1. 清掉 npm 的快取:

npm cache clean

 

2. 重裝 Cordova:

npm uninstall -g cordova
npm install -g cordova

 

3. 移除 ~/.cordova 目錄

rm -rf ~/.cordova

 

4. 升級 npm

npm update -g npm

 

後來看到有人說它升級了 node.js…

死馬當活馬醫,去 node.js 網站上抓了 Mac 版最新的 node.js 來安裝,

原本:node: 6.2.1, npm: 3.9.3

後來:node: 6.10.3, npm: 3.10.10

 

這邊比較怪的是,之前我用 npm update -g npm,

最多也只升到 3.9.10,不知道為啥沒辦法升到附在 node.js 裡的 npm 3.10.10?

不過,升完 node.js 之後,問題消失了,

不確定是升級 node.js 還是 npm 的效果:

testuser@localhost ~ $ cordova platform add ios

Using cordova-fetch for cordova-ios@^4.4.0
Adding ios project...
Creating Cordova project for the iOS platform:
    Path: platforms/ios
    Package: idv.ephrain.multilibrarylogin
    Name: Library Multi-Login
iOS project created with cordova-ios@4.4.0
Installing "cordova-plugin-admobpro" for ios
Plugin dependency "cordova-plugin-extension@1.5.1" already fetched, using that version.
Installing "cordova-plugin-extension" for ios
Installing "cordova-plugin-dialogs" for ios
Dependent plugin "cordova-plugin-extension" already installed on ios.
Installing "cordova-plugin-inappbrowser" for ios
Installing "cordova-plugin-statusbar" for ios
Installing "cordova-plugin-whitelist" for ios
--save flag or autosave detected
Saving ios@~4.4.0 into config.xml file ...

 

總之,有遇到問題的人,可以每個方法都嘗試看看… Orz

(本頁面已被瀏覽過 1,830 次)

2 thoughts on “[Cordova] 增加 ios platform 時,出現 Failed to fetch platform cordova-ios 的問題

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料