Skip to content Skip to sidebar Skip to footer

"require" Exception In Cordova/phonegap Project

I am trying to build an hybrid mobile app using Phonegap/Cordova in Android platform. And I have succeeded in that too :) The app works as desired in Ripple emulator in my Chrome b

Solution 1:

Dont use the plugins *.js files out of the plugin source.

Dont add plugins *.js files as tags into your html (Cordova loads them on its own based on cordova_plugins.js )

The specific error 'require is not defined' comes from missing cordova define in the plugins.js

cordova.define("org.apache.cordova.file.DirectoryEntry", function(require, exports, module) {

});

To avoid all of this trouble:

Use cordova command line interface to setup platforms and plugins. It manages all the native and javascript source files and puts them together in the proper way.

Solution 2:

Cordova and Phonegap are pretty much the same thing, you shouldn't need to download both. Cordova is the open source project that helps you publish your HTML5 app to multiple different mobile OSes. Phonegap uses Cordova to do that, but also adds some extra features, mostly just being able to build in the cloud instead of on your workstation.

Node.js is used by Cordova for a lot of the building steps. Since Cordova works on OSX and Windows machines, we needed a way to write build and package scripts that would work on both operating systems - node.js provides this. When you build an application with Cordova you shouldn't really use node.js at all, unless you are also building a complementary backend system.

Starting with Cordova 3.x, there is a cordova command line tool that can greatly help you create the application. It takes care of copying the right cordova.js and cordova-android.jar files. You can read about it here http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface

Once you get set up you might want to read my other answer that clarifies some of the use cases of cordova tool: Should a phonegap plugin be declared in the config.xml file?

Post a Comment for ""require" Exception In Cordova/phonegap Project"