简体   繁体   中英

TypeError: 'undefined' is not a function (evaluating 'cordova.exec') with Sencha Touch and Cordova 3.0

I'm working on a POC project with Apache Cordova 3.0 and Sencha Touch 2.3. Things were working fine for a while but now whenever I attempt to invoke code in Cordova that calls down to my custom plugin it fails because of the error in the title.

I know for a fact that the onDeviceReady event is being fired because I listen for it and throw up an alert popup when it is received, and the alert fires every time.

Not sure what else to check or what other details to provide?

This error explains that your custom plugin is not correctly configured in your app.

1) Have you included the custom plugin's js file in your page? Add the .js file after cordova.js and before using your custom plugin's feature.

2) How you have added the custom plugin to your project? Its always recommended to use the CLI tool to add/remove any plugin.

I'm faced the same problem. it seems that Adobe made a really mess in the move from 2.x to 3.x.

What I'm doing in my plugins is checking for cordova.exec and requiring it if not defined. For example, at very top source code of your plugin add the following:

 var cordova = require('cordova');
 cordova.exec = cordova.exec || require('cordova/exec');

This should do the trick.

Best regards,

Eric

Found the problem - I was loading cordova.js explicitly in my index.html. But Sencha touch was also loading cordova.js explicitly in a non-obvious way(automatically specified in app.json). Once I removed my own cordova.js inclusion it loaded fine.

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