简体   繁体   中英

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. 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:

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? Is the "module.export" from the iCloudKV plugin importable in some way with a require() or something? 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. 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:

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

...and then I could reference it properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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