简体   繁体   English

TypeError:“未定义”不是Sencha Touch和Cordova 3.0的函数(评估“ cordova.exec”)

[英]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. 我正在使用Apache Cordova 3.0和Sencha Touch 2.3进行POC项目。 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. 一段时间以来一切正常,但是现在每当我尝试在Cordova中调用调用我的自定义插件的代码时,都会由于标题错误而失败。

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. 我知道onDeviceReady事件正在被触发是因为我侦听该事件并在接收到它时抛出警报弹出窗口,并且警报每次都触发。

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? 1)您是否在页面中包含了自定义插件的js文件? Add the .js file after cordova.js and before using your custom plugin's feature. 在cordova.js之后和使用自定义插件的功能之前,添加.js文件。

2) How you have added the custom plugin to your project? 2)您如何将自定义插件添加到项目中? Its always recommended to use the CLI tool to add/remove any plugin. 始终建议使用CLI工具添加/删除任何插件。

I'm faced the same problem. 我遇到了同样的问题。 it seems that Adobe made a really mess in the move from 2.x to 3.x. 看来Adobe在从2.x升级到3.x的过程中真是一团糟。

What I'm doing in my plugins is checking for cordova.exec and requiring it if not defined. 我在插件中所做的就是检查cordova.exec并要求它(如果未定义)。 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. 发现了问题-我在index.html中显式加载了cordova.js。 But Sencha touch was also loading cordova.js explicitly in a non-obvious way(automatically specified in app.json). 但是,Sencha touch还以一种非显而易见的方式(在app.json中自动指定)显式加载了cordova.js。 Once I removed my own cordova.js inclusion it loaded fine. 一旦我删除了自己的cordova.js包含文件,它就会很好地加载。

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

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