我有一个问题,我认为这与我的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
当我尝试运行failed(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": {}
}
}
}
谢谢!
1> 小智..:
添加本地插件时,我收到了相同的错误消息: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
标志来使用旧的获取逻辑来获取平台和插件.
这应该是公认的答案.接受的答案中的链接甚至提到了这个标志.
那么现在我们还有一个替代方案--nofetch已经消失了吗?
`--nofetch`标志是否保存到`package.json` - 它似乎不适合我,因此,在新克隆上运行`cordova prepare`会产生相同的错误.
Cordova 8.0.0中删除了`--nofetch`选项:https://issues.apache.org/jira/browse/CB-13055
2> RafaelKr..:
编辑:这个答案已经过时了.请使用uutrecht的答案.
我现在遇到了同样的问题.我通过将cordova从v7.0.0降级到v6.5.0来修复它
npm i -g cordova@6.5.0
他们改变了获取插件的方式.https://cordova.apache.org/news/2017/05/04/cordova-7.html
3> Mukesh Chapa..:
--nofetch
选项已在Cordova版本8.0.0中删除:https : //issues.apache.org/jira/browse/CB-13055
如果您已经安装了Cordova 8.xx,则可以将其降级到7.1.0版本,然后使用该--nofetch
选项。
运行以下命令将Cordova降级到7.1.0:
npm install -g cordova@7.1.0
如果上述命令不起作用,请先尝试卸载cordova,然后再安装7.1.0版的cordova:
npm uninstall -g cordova
npm install -g cordova@7.1.0
然后,检查Cordova版本以确认其是否已降级:
cordova --version