简体   繁体   English

编写具有依赖项的Cordova插件:ReferenceError:找不到变量

[英]Writing a Cordova Plugin with a dependency: ReferenceError: Can't find variable

I'm attempting to write a cordova plugin that depends on another plugin. 我正在尝试编写依赖于另一个插件的cordova插件。 My plugin specifies a dependency like so: 我的插件指定了类似的依赖项:

<dependency id="fr.pierrickrouxel.cordova.plugin.iCloudKV" url="https://github.com/pierrickrouxel/phonegap-icloudkv-plugin.git" />

Then, in my .js component, I attempt to reference the 'iCloudKV' javascript variable that is exported by the dependent plugin, but I get this error: 然后,在我的.js组件中,我尝试引用由相关插件导出的'iCloudKV'JavaScript变量,但出现此错误:

ReferenceError: Can't find variable: iCloudKV, http://172.20.1.101:8101/cordova.js, Line: 71

Is there an approved way to reference javascript in dependent plugins? 有没有批准的方法可以在依赖插件中引用javascript? Is the "module.export" from the iCloudKV plugin importable in some way with a require() or something? iCloudKV插件中的“ module.export”是否可以通过require()之类的方式导入? I've tried the obvious things, but nothing seems to match. 我已经尝试了显而易见的事情,但似乎没有任何匹配。

The issue is that I needed to require() the javascript portion of the iCloudCV plugin. 问题是我需要require()iCloudCV插件的javascript部分。 The module that is exported by cordova is prefixed by the plugin's id, so the full code to include the "iCloudCV" variable in the "fr.pierrickrouxel.cordova.plugin.iCloudKV" plugin is: cordova导出的模块的前缀为插件的ID,因此在“ fr.pierrickrouxel.cordova.plugin.iCloudKV”插件中包含“ iCloudCV”变量的完整代码为:

var iCloudKV = require("fr.pierrickrouxel.cordova.plugin.iCloudKV.iCloudKV");

...and then I could reference it properly. ...然后我可以正确地引用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM