安装科尔多瓦插件时出错
Posted
技术标签:
【中文标题】安装科尔多瓦插件时出错【英文标题】:Error installing cordova plugin 【发布时间】:2017-11-22 14:32:05 【问题描述】:我正在开发一个依赖于其他插件的 cordova 插件。如果不传递 --fetch 参数,我将无法安装插件。
这是我的插件依赖项在原始插件的 xml 文件中的样子:
<dependency url="https://bitbucket.org/MY_REPO_URL" id="SOME_PLUGIN_ID"/>
<dependency url="https://bitbucket.org/MY_REPO_URL" id="SOME_OTHER_PLUGIN_ID" subdir="SOME_SUBDIR"/>
当我尝试在不使用 --nofetch 的情况下安装原始插件时:
cordova plugin add ORIGINAL_PLUGIN_ID
我收到以下错误:
No scripts found for hook "before_plugin_add".
No version specified for SOME_PLUGIN_NAME, retrieving version from package.json
Calling plugman.fetch on plugin "SOME_PLUGIN_NAME@^2.4.3"
saving
Running command: npm install SOME_PLUGIN_NAME@^2.4.3 --production --save
Command finished with error code 0: npm install,SOME_PLUGIN_NAME@^2.4.3,--production,--save
Copying plugin ".../test/node_modules/ORIGINAL_PLUGIN_ID" => ".../test/plugins/ORIGIAL_PLUGIN_ID"
Calling plugman.install on plugin ".../test/plugins/ORIGINAL_PLUGIN_ID" for platform "android
Installing "ORIGINAL_PLUGIN_ID" for android
Running command: .../test/platforms/android/cordova/version
Command finished with error code 0: .../test/platforms/android/cordova/version
Dependencies detected, iterating through them...
Requesting plugin "SOME_PLUGIN_ID".
Plugin dependency "SOME_PLUGIN_ID" not fetched, retrieving then installing.
saving
Running command: npm install https://bitbucket.org/MY_REPO_URL --production --save
Command finished with error code 0: npm install,https://bitbucket.org/MY_REPO_URL,--production,--save
Failed to install 'ORIGINAL_PLUGIN_ID': Error
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:215:37
at _rejected (/usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:864:24)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:890:30
at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:1142:31)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:808:41)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:624:44
at runSingle (/usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:137:13)
at flush (/usr/local/lib/node_modules/cordova/node_modules/cordova-fetch/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
Error: Failed to fetch plugin https://bitbucket.org/MY_REPO_URL via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
TypeError: Parameter "url" must be a string, not undefined
如果我使用--nofetch,安装就完美了。
cordova plugin add ORIGINAL_PLUGIN_NAME --nofetch
我想知道是否有什么我可以做的,以便我可以在不使用 --nofetch
的情况下添加插件【问题讨论】:
我还没有测试通过 npm 设置依赖项,我想知道这是否会解决它,或者我会添加两次插件。 【参考方案1】:我们通过在 npm 中发布依赖项并删除 subdir 和 url 属性(只需添加插件 id)解决了这个问题。
现在我们可以将不带 --nofetch 的插件添加到项目中。
我还发现 subdir 功能在 cordova 内部已被弃用,因为 npm 成为默认选项。不幸的是,这没有记录在案,依赖项的 subdir 选项是 still documented 作为受支持且未弃用的功能。
【讨论】:
以上是关于安装科尔多瓦插件时出错的主要内容,如果未能解决你的问题,请参考以下文章