无法获得已安装模块

时间:2017-05-08 19:56:09

标签: git cordova ionic-framework

我有一个问题,我认为这与我的package.json或cordova平台的版本有关。

当我尝试运行ionic state restore时,它会返回以下输出:

Attempting to restore your Ionic application from package.json

Restoring Platforms

cordova platform add ios
cordova platform add android

Restore platforms is complete

Restoring Plugins

cordova plugin add cordova-plugin-whitelist
cordova plugin add cordova-plugin-console
cordova plugin add cordova-plugin-statusbar
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-splashscreen
cordova plugin add ionic-plugin-keyboard
cordova plugin add cordova-plugin-network-information
cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-compat
cordova plugin add cordova-plugin-media
cordova plugin add https://github.com/AubreyHewes/cordova-background-audio.git
Caught exception:
 undefined

Mind letting us know? https://github.com/driftyco/ionic-cli/issues

当我尝试运行失败的命令(cordova plugin add https://github.com/AubreyHewes/cordova-background-audio.git)时,它会返回以下错误:

Error: Failed to fetch plugin git+https://github.com/AubreyHewes/cordova-background-audio.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Failed to get absolute path to installed module

我不明白为什么它说这是一个连接问题,因为我的网络连接工作得很好。插件的URL也是正确的。

我的环境信息:

Cordova CLI: 7.0.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: 1.9.0
ios-sim version: 5.0.10
OS: OS X El Capitan
Node Version: v7.0.0
Xcode version: Xcode 8.1 Build version 8B62

我为这个问题拔出了头发。你有什么可能导致这个问题的线索吗?

我的package.json内容:

{
  "name": "paranaiba-app",
  "version": "1.1.1",
  "description": "paranaiba-app: An Ionic project",
  "dependencies": {
    "cordova-android": "^6.2.3",
    "cordova-ios": "^4.4.0",
    "cordova-plugin-compat": "~1.1.0",
    "cordova-plugin-console": "~1.0.6",
    "cordova-plugin-device": "~1.1.5",
    "cordova-plugin-file": "~4.3.2",
    "cordova-plugin-media": "~2.4.1",
    "cordova-plugin-music-controls": "git+https://github.com/homerours/cordova-music-controls-plugin.git",
    "cordova-plugin-network-information": "~1.3.2",
    "cordova-plugin-splashscreen": "~4.0.2",
    "cordova-plugin-statusbar": "~2.2.2",
    "cordova-plugin-whitelist": "~1.3.2",
    "gulp": "^3.5.6",
    "gulp-concat": "^2.2.0",
    "gulp-minify-css": "^0.3.0",
    "gulp-rename": "^1.2.0",
    "gulp-sass": "^2.0.4",
    "ionic-plugin-keyboard": "~2.2.1",
    "nl.kingsquare.cordova.background-audio": "git+https://github.com/AubreyHewes/cordova-background-audio.git",
    "phonegap-plugin-push": "~1.8.4"
  },
  "devDependencies": {
    "bower": "^1.3.3",
    "gulp-util": "^2.2.14",
    "shelljs": "^0.3.0"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard",
    "cordova-plugin-network-information",
    "cordova-plugin-file",
    "cordova-plugin-compat",
    "cordova-plugin-media",
    {
      "locator": "https://github.com/AubreyHewes/cordova-background-audio.git",
      "id": "nl.kingsquare.cordova.background-audio"
    },
    {
      "locator": "https://github.com/homerours/cordova-music-controls-plugin",
      "id": "cordova-plugin-music-controls"
    }
  ],
  "cordovaPlatforms": [
    {
      "platform": "ios",
      "version": "",
      "locator": "ios"
    },
    {
      "platform": "android",
      "version": "",
      "locator": "android"
    }
  ],
  "cordova": {
    "platforms": [
      "android",
      "ios"
    ],
    "plugins": {
      "phonegap-plugin-push": {
        "SENDER_ID": "XXXX"
      },
      "cordova-plugin-whitelist": {},
      "cordova-plugin-console": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-file": {},
      "cordova-plugin-compat": {},
      "cordova-plugin-media": {},
      "nl.kingsquare.cordova.background-audio": {},
      "cordova-plugin-music-controls": {}
    }
  }
}

谢谢!

7 个答案:

答案 0 :(得分:77)

添加本地插件时收到了相同的错误消息:Error: Failed to get absolute path to installed module

使用选项--nofetch(cordova@7.0.1)修复它:

cordova plugin add ../my-plugin --nofetch

根据https://github.com/apache/cordova-cli/blob/master/RELEASENOTES.md: 使用--nofetch标志来使用旧的获取逻辑来获取平台和插件。

答案 1 :(得分:12)

编辑:这个答案已经过时了。请改用answer of uutrecht

我现在遇到了同样的问题。我通过将cordova从v7.0.0降级到v6.5.0

来修复它

{{1}}

他们改变了获取插件的方式。 https://cordova.apache.org/news/2017/05/04/cordova-7.html

答案 2 :(得分:5)

Cordova版本8.0.0中删除了

--nofetch选项:https://issues.apache.org/jira/browse/CB-13055

如果您已经安装了Cordova 8.x.x,那么可以将其降级到7.1.0版,然后使用--nofetch选项。

运行以下命令将Cordova降级为7.1.0:

npm install -g cordova@7.1.0

如果上述命令不起作用,请先尝试卸载cordova,然后再安装cordova版本7.1.0:

npm uninstall -g cordova
npm install -g cordova@7.1.0

然后,检查Cordova版本以确认它是否降级:

cordova --version

答案 3 :(得分:4)

从config.xml,package.json和package-lock.json中删除从本地安装的插件。

然后再试一次。 我为大多数情况工作。

{
    "name": "io.cordova.hellocordova",
    "version": "1.0.0",
    "displayName": "HelloCordova",
    "cordova": {
        "platforms": [
            "android"
        ],
        "plugins": {
            "cordova-plugin-whitelist": {},
            "com-example-plugin": {}
        }
    },
    "dependencies": {
        "cordova-android": "^6.2.3",
        "cordova-plugin-template": "file:../cordova-testplugin",  // <-- remove this line
        "cordova-plugin-whitelist": "^1.3.2"
    }
}

答案 4 :(得分:0)

此答案适用于:Cordova 8.1.2(cordova-lib@8.1.1)

在我的情况下,这与git+https://...中依赖项下列出的网址的package.json部分有关。将其更改为https://...就可以了。

在cordova s​​rc中,他们使用模块cordova-fetch。在函数getPath中引发错误。它可能会调用searchDirForTarget,后者又会调用模块is-url。目标,例如url,在此处得到验证,git+https://...无效,因为它与/^(?:\w+:)?\/\/(\S+)$/不匹配。

答案 5 :(得分:0)

我通过以下命令修复了它(使用cordova v 8.1.2):

ionic cordova rm PLUGIN_NAME && ionic cordova add PLUGIN_NAME

答案 6 :(得分:0)

我认为问题是插件的package.json的ID与git repo名称不同

例如:   package.json的ID => com.abc.cde   git网址必须为https://github.com/ {username} /com.abc.cde.git