Cordova的难度 - 无法添加插件(甚至是核心插件)

时间:2021-12-23 16:32:44

I'm following the official Apache Cordova tutorial to create an app in Cordova on Mac OSX.

我正在遵循官方的Apache Cordova教程,在Mac OSX上的Cordova中创建一个应用程序。

For command

cordova plugin add cordova-plugin-(anything)

Terminal throws error

终端抛出错误

Error: Failed to fetch package information for cordova-plugin-(anything)

For example, core plugins "cordova-plugin-device" AND "cordova-plugin-console" both fail with this error.

例如,核心插件“cordova-plugin-device”和“cordova-plugin-console”都会因此错误而失败。

I've read several two-year-old SO questions that suggest it's a firewall issue, but I've downloaded npm, Cordova and a bunch of other things through Terminal. Is it really a firewall issue? If so, how to fix?

我已经阅读了几个两年前的SO问题,这些问题表明这是一个防火墙问题,但我已经通过终端下载了npm,Cordova和其他一些东西。它真的是防火墙问题吗?如果是这样,如何解决?

If it's not a firewall issue, why is Cordova failing to fetch and add the plugins, and what is the way to solve?

如果它不是防火墙问题,为什么Cordova无法获取和添加插件,以及解决方法是什么?

Here's the error output.

这是错误输出。

deborahs-MBP:hybrid-test deborah$ cordova plugin add cordova-plugin-device
Fetching plugin "cordova-plugin-device" via plugin registry
Error: Failed to fetch package information for cordova-plugin-device
    at     /Users/deborah/.node/lib/node_modules/cordova/node_modules/plugman/src/registry/registry.js:32:20
    at Request.cb [as _callback]     (/Users/deborah/.node/lib/node_modules/cordova/node_modules/plugman/src/registry/registry.js:251:9)
    at self.callback (/Users/deborah/.node/lib/node_modules/cordova/node_modules/plugman/node_modules/request/index.js:148:22)
    at emitOne (events.js:95:20)
    at Request.emit (events.js:182:7)
    at ClientRequest.self.clientErrorHandler (/Users/deborah/.node/lib/node_modules/cordova/node_modules/plugman/node_modules/request/index.js:257:10)
    at emitOne (events.js:90:13)
    at ClientRequest.emit (events.js:182:7)
    at Socket.socketErrorListener (_http_client.js:306:9)
    at emitOne (events.js:90:13)

1 个解决方案

#1


1  

Note I had a second Cordova problem posted that turned out to be related to the same issue. This process below resolved both issues.

注意我发布了第二个Cordova问题,结果与同一个问题有关。以下流程解决了这两个问题。


Somewhere between Node and npm there is a problem that affects Cordova installation. This problem did not resolve without the following steps. Sorry the steps are not as clear as I would like but hope it will help someone.

Node和npm之间存在一个影响Cordova安装的问题。没有以下步骤,此问题无法解决。对不起,这些步骤并不像我希望的那样清楚,但希望它会对某人有所帮助。

  1. sudo uninstall -g cordova
  2. sudo uninstall -g cordova

  3. re-install Node using the MacOSX package installer on the Node site
  4. 使用Node站点上的MacOSX软件包安装程序重新安装Node

  5. update npm according to npm documentation
  6. 根据npm文档更新npm

  7. sudo install -g cordova
  8. sudo安装-g cordova

  9. fix the "minimatch deprecated" error with npm update -g minimatch@3.0.2
  10. 使用npm update -g minimatch@3.0.2修复“minimatch deprecated”错误

  11. now create a Cordova project
  12. 现在创建一个Cordova项目

  13. 'cordova add platform ios'
  14. 'cordova add platform ios'

  15. 'cordova add platform android'
  16. 'cordova add platform android'

Now,

cordova plugin add cordova-plugin-*

works.

#1


1  

Note I had a second Cordova problem posted that turned out to be related to the same issue. This process below resolved both issues.

注意我发布了第二个Cordova问题,结果与同一个问题有关。以下流程解决了这两个问题。


Somewhere between Node and npm there is a problem that affects Cordova installation. This problem did not resolve without the following steps. Sorry the steps are not as clear as I would like but hope it will help someone.

Node和npm之间存在一个影响Cordova安装的问题。没有以下步骤,此问题无法解决。对不起,这些步骤并不像我希望的那样清楚,但希望它会对某人有所帮助。

  1. sudo uninstall -g cordova
  2. sudo uninstall -g cordova

  3. re-install Node using the MacOSX package installer on the Node site
  4. 使用Node站点上的MacOSX软件包安装程序重新安装Node

  5. update npm according to npm documentation
  6. 根据npm文档更新npm

  7. sudo install -g cordova
  8. sudo安装-g cordova

  9. fix the "minimatch deprecated" error with npm update -g minimatch@3.0.2
  10. 使用npm update -g minimatch@3.0.2修复“minimatch deprecated”错误

  11. now create a Cordova project
  12. 现在创建一个Cordova项目

  13. 'cordova add platform ios'
  14. 'cordova add platform ios'

  15. 'cordova add platform android'
  16. 'cordova add platform android'

Now,

cordova plugin add cordova-plugin-*

works.