如何修复无法获取平台cordova-ios@~4.4.0

当我使用“cordova platform add ios”命令获取最新的Cordova版本7.0.1时,我收到一条无法获取的消息。

我正在尝试将现有项目升级到iOS版本4.4.0,但为了让我高枕无忧,我尝试创建一个同样出错的新项目。

以下是我的终端输出,显示我收到的错误,是否有人可以推荐解决此问题的解决方案?

Stuarts-MacBook-Pro:T Stu$ cordova create myApp org.apache.cordova.myApp myApp Creating a new cordova project. Stuarts-MacBook-Pro:T Stu$ cd myApp Stuarts-MacBook-Pro:myApp Stu$ 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. Failed to get absolute path to installed module Stuarts-MacBook-Pro:myApp Stu$ 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 WARN org.apache.cordova.myapp@1.0.0 No repository field. npm ERR! Darwin 16.0.0 npm ERR! argv "/usr/local/Cellar/node/6.2.0/bin/node" "/usr/local/bin/npm" "install" "cordova-ios@^4.4.0" "--save" npm ERR! node v6.2.0 npm ERR! npm v3.8.9 npm ERR! path /Users/S/Development/T/myApp/node_modules/.staging/xml-escape-d330e1e1 npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall rename npm ERR! enoent ENOENT: no such file or directory, rename '/Users/S/Development/T/myApp/node_modules/.staging/xml-escape-d330e1e1' -> '/Users/S/Development/T/myApp/node_modules/cordova-ios/node_modules/xml-escape' 

我已经解决了这个问题,它似乎是一个NPM问题而不是Cordova问题。 我刚刚更新了终端内的NPM,更新后“cordova platform add ios”工作正常。 快乐的日子 – 1!

 npm update -g 
  1. 删除位于node_modules/cordova-ios的文件夹node_modules/cordova-ios

  2. 键入以下命令

     ionic cordova build ios 

有时,以前添加的平台未正确删除,因此会出现此类问题。 按命令删除平台并再次添加..

请遵循以下步骤:

  1. 运行命令

     ionic cordova platform remove ios 
  2. 运行命令:

     ionic cordova platform add ios --save` 
  3. 如果您仍然遇到问题 ,请尝试重新运行:

     ionic cordova platform remove ios --save 

注意:通过再次运行命令ionic cordova platform remove ios --save获取更新版本的ios平台。
例如:

  • 第一次: cordova-fetch for cordova-ios@~4.5.1
  • 第二次: cordova-fetch for cordova-ios@~4.5.4