安装cordova插件时出错

时间:2017-11-22 14:32:06

标签: cordova cordova-plugins

我正在开发一个与其他插件有依赖关系的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

1 个答案:

答案 0 :(得分:1)

我们通过在npm中发布依赖项并删除了subdir和url属性(只是添加插件ID)来解决这个问题。

现在我们可以将没有 - nofetch 的插件添加到项目中。

我还发现 subdir 功能在cordova内部被弃用,因为npm成为默认选项。遗憾的是,这没有记录,依赖项的subdir选项是still documented作为受支持和不推荐的功能。