git 无法获得已安装模块的绝对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43856285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to get absolute path to installed module
提问by Gabriel Ferreira Rosalino
I'm with a problem that I believe that is something related to my package.json or the version of the cordova platform.
我遇到了一个问题,我认为这与我的 package.json 或cordova 平台的版本有关。
When I try to run an ionic state restore
it returns the following output:
当我尝试运行时,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
And when I try to run the command that failed (cordova plugin add https://github.com/AubreyHewes/cordova-background-audio.git
), it returns the following error:
当我尝试运行失败的命令 ( 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
I don't understand why it says that is a connection problem, because my internet connection is working just fine. Also the URL of the plugin is right too.
我不明白为什么它说这是一个连接问题,因为我的互联网连接工作正常。插件的 URL 也是正确的。
My environment info:
我的环境信息:
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
I'm pulling my hairs out for this problem. Do you have a clue of what can be causing this?
我正在为这个问题拔毛。你知道是什么导致了这种情况吗?
My package.json content:
我的 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": {}
}
}
}
Thank you!
谢谢!
回答by uutecht
I got the same error message when adding a local plugin: Error: Failed to get absolute path to installed module
.
添加本地插件的时候,我得到了同样的错误信息:Error: Failed to get absolute path to installed module
。
Using the option --nofetch
([email protected]) fixed it:
使用选项--nofetch
([email protected]) 修复它:
cordova plugin add ../my-plugin --nofetch
cordova plugin add ../my-plugin --nofetch
According to https://github.com/apache/cordova-cli/blob/master/RELEASENOTES.md:
Use --nofetch
flag to fetch platforms and plugins using old fetching logic.
根据https://github.com/apache/cordova-cli/blob/master/RELEASENOTES.md:使用--nofetch
标志使用旧的获取逻辑来获取平台和插件。
回答by RafaelKr
Edit: This answer is outdated. Please use the answer of uutrechtinstead.
I had the same problem right now. I fixed it by downgrading cordova from v7.0.0 to v6.5.0
我现在遇到了同样的问题。我通过将cordova从v7.0.0降级到v6.5.0来修复它
npm i -g [email protected]
npm i -g [email protected]
They changed the way how they fetch the plugins. https://cordova.apache.org/news/2017/05/04/cordova-7.html
他们改变了获取插件的方式。https://cordova.apache.org/news/2017/05/04/cordova-7.html
回答by Mukesh Chapagain
--nofetch
option has been removed in Cordova version 8.0.0: https://issues.apache.org/jira/browse/CB-13055
--nofetch
选项已在 Cordova 8.0.0 版中删除:https: //issues.apache.org/jira/browse/CB-13055
If you have already installed Cordova 8.x.x then you can downgrade it to version 7.1.0 and then use the --nofetch
option.
如果您已经安装了 Cordova 8.xx,那么您可以将其降级到 7.1.0 版,然后使用该--nofetch
选项。
Run the following command to downgrade Cordova to 7.1.0:
运行以下命令将 Cordova 降级到 7.1.0:
npm install -g [email protected]
If the above command doesn't work, then try uninstalling cordova at first and then install cordova version 7.1.0:
如果上面的命令不起作用,那么首先尝试卸载cordova,然后安装cordova 7.1.0版:
npm uninstall -g cordova
npm install -g [email protected]
Then, check the Cordova version to confirm if it's downgraded or not:
然后,检查 Cordova 版本以确认它是否降级:
cordova --version
回答by wf9a5m75
Remove the plugin, you installed from local, from the config.xml, the package.json and the package-lock.json.
从 config.xml、package.json 和 package-lock.json 中删除您从本地安装的插件。
Then try again. I work for most of cases.
然后再试一次。我为大多数情况工作。
{
"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"
}
}
回答by Erik
This answer applies to: Cordova 8.1.2 ([email protected])
此答案适用于:Cordova 8.1.2 ([email protected])
In my case, it had to do with git+https://...
part of the url, listed in package.json
under dependencies. Changing it to https://...
did the trick.
就我而言,它与git+https://...
url 的一部分有关,package.json
在依赖项下列出。改变它就行https://...
了。
In the cordova src they use a module cordova-fetch
. In the function getPath
the error is thrown. It might call searchDirForTarget
which in turn calls module is-url
. The target, e.g. the url, gets validated here and git+https://...
yields invalid because it does not match /^(?:\w+:)?\/\/(\S+)$/
.
在cordova src中,他们使用一个模块cordova-fetch
。在函数getPath
中抛出错误。它可能会调用searchDirForTarget
,而后者又会调用 module is-url
。目标,例如 url,在此处得到验证并git+https://...
产生无效,因为它不匹配/^(?:\w+:)?\/\/(\S+)$/
。
回答by Christopher Kiessling
I fixed it running the folowing command (using cordova v 8.1.2):
我修复了它运行以下命令(使用cordova v 8.1.2):
ionic cordova plugin rm PLUGIN_NAME && ionic cordova plugin add PLUGIN_NAME
ionic cordova plugin rm PLUGIN_NAME && ionic cordova plugin add PLUGIN_NAME
回答by Dun Grady
I think the problem is the id of plugin's package.json different with git repo name
我认为问题是插件的 package.json 的 id 与 git repo 名称不同
for example: id of package.json => com.abc.cde the git url must be https://github.com/{username}/com.abc.cde.git
例如:package.json 的 id => com.abc.cde git url 必须是https://github.com/{username}/com.abc.cde.git