Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostic is undefined #2

Closed
jabas06 opened this issue Sep 3, 2015 · 1 comment
Closed

diagnostic is undefined #2

jabas06 opened this issue Sep 3, 2015 · 1 comment

Comments

@jabas06
Copy link

jabas06 commented Sep 3, 2015

If I access the plugin through cordova.plugins.diagnostic I get an error because is undefined.

I solved it accessing the plugin like this -> window.Diagnostic (with a capital D)

@dpa99c
Copy link
Owner

dpa99c commented Sep 3, 2015

If the plugin is installed correctly into a Cordova 3.0+ project, the cordova.plugins.diagnostic object is created by the cordova plugin mechanism; you can see this in the plugin's plugin.xml:

<clobbers target="cordova.plugins.diagnostic" />

It can then be referenced as cordova.plugins.diagnostic from the app; see the example project source code

When the plugin is installed via cordova plugin add cordova-diagnostic-plugin, cordova will wrap the contents of the Javascript module to expose the object above. For example, for the Android platform you should end up with the file platforms/android/assets/www/plugins/cordova.plugins.diagnostic/www/android/diagnostic.js

and it should look like:

cordova.define("cordova.plugins.diagnostic.Diagnostic", function(require, exports, module) {
  var Diagnostic = function() {
  };
  ...
  module.exports = new Diagnostic();
});

If cordova.plugins.diagnostic is not defined but window.Diagnostic is, it means the plugin hasn't been installed correctly so the cordova.define wrapper is missing and Diagnostic is being declared as a variable in global scope.

This is not an issue with the plugin, hence closing the issue.

@dpa99c dpa99c closed this as completed Sep 3, 2015
dpa99c pushed a commit that referenced this issue Mar 26, 2022
Bumping minimist package version to resolve security audit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants