I'm new to Cordova and am figuring out how to include a Node.JS Plugin, this one:
https://github.com/mateodelnorte/forecast.io
I've tried to include the JS file manually, but when running the code,
of course I get the error that "require is not defined".
After Googling I found out that I have to use Cordova package manager to install such plugins.
however,
there is no plugin for Forecast.io... So,
how to use this nodejs-plugin?
Do I need to create a Cordova plugin myself?
Related
I am new to Javascript and am interested in using a library from github. I am using netbeans to code and I have installed node.js. However, I am still getting the error 'Require is not defined'. I have installed 'browserify' as this seemed like a common solution, but I am still getting this error.
Am I doing something wrong?
Image of set up libraries
Update
I have also found that there is a problem with one of my libraries, think it could be relevant to the original problem.
Problem with library
If you are developing NodeJS based project, you should use NodeJS project type in NetBeans where require() is considered as known global function and as such NetBeans won't show the hint.You can change your current project to enable NodeJS support by right clicking on the project, select Project Properties -> NodeJS and check Enable NodeJS support.
If you are using RequireJS library, you can also enable RequireJS support in Project Properties in JavaScript Frameworks -> RequireJS
I guess this is because require() does not exist in the browser/client-side JavaScript.Can you give it a try to following statements;
Use <script> tag.
Use a CommmonJS implementation. Synchronous
dependencies like Node.js
Use an AMD implementation.
And keep library codes and application codes seperated. ( bundle.js and script.js )
Browserify will take all the script files necessary and put them into the "bundle.js" file, so you should only have to include "bundle.js" in the HTML file, not the "script.js" file.
I am using the following version of IONIC and Cordova;
IONIC;
1.5.5
Cordova;
5.1.1
Build my mobile application.
But when ever I finish building it and run it I keep getting the following exception:
Uncaught module cordova-plugin-file.ProgressEvent not found
Could someone please help me out ?.
I had the same issue today and in my case this was because the version of the file-transfer plugin was not compatible with the File plugin I use.
The file transfer plugin requires the cordova-plugin-file.ProgressEvent (see FileTransfer.js in the file transfer plugin directory)
But if you're still using an older version of the file plugin (in my case org.apache.cordova.file instead of cordova-plugin-file) then it can't resolve that.
So either you update your plugins so you use the cordova-file-plugin or you change the code of the FileTransfer plugin, this is not advised because when the plugins are reinstalled you will loose this change. But if for whatever reason you can't use the newer file plugin you can use this method.
On line 25 of the FileTransfer.js file change
ProgressEvent = require('cordova-plugin-file.ProgressEvent');
to
ProgressEvent = require('org.apache.cordova.file.ProgressEvent');
If that doesn't solve it, try to look up the correct module name in your File plugin directory's config.xml file (look for the ID property) and use that instead (don't forget to append ProgressEvent)
To elaborate on my point of not changing the code of the FileTransfer plugin you can however copy the plugin code and put it somewhere on your disk and use that plugin instead of the hosted one (which is loaded and used if you just use the plugin's ID)
I've been following tutorials to set up a PhoneGap project (Android) on Eclipse, I'm fairly new to JS frameworks so I'm setting it up to start learning how to use them. In the tutorial (and any other I watch), they use an older version of PhoneGap that includes a .jar file and that isn't present with the latest version. I'm guessing it will still be easy to do but I'm just missing something obvious.
Is there another way to set it up now? Or do I simply not need this file? Thank you for any help.
The Documentation specifically shows how to open up the project in Eclipse.
Use the cordova utility to set up a new project, as described in The Cordova The Command-Line Interface. For example, in a source-code directory:
$ cordova create hello com.example.hello "HelloWorld"
$ cd hello
$ cordova platform add android
$ cordova build
Launch the Eclipse Application.
Select New Project menu item.
Choose Android Project from Existing Code from the resulting dialog box, and press Next:
Navigate to hello, or whichever directory you created for the project, then to the platforms/android subdirectory.
Make sure both hello and hello-CordovaLib projects are selected to be imported. The hello-CordovaLib project is needed as of Cordova 3.3.0 because Cordova is now used as an Android Library instead of a .jar file
Press Finish.
This is all in the documentation.
I'm currently building an Application with PhoneGap(3.3). When i try to get the API to work i always get the error:
for example:
"Cannot call method 'vibrate' of undefined
What i did:
phonegap create appname com.myname.appname appname
phonegap local build android
phonegap plugin add XXXXXX plugin path (gave me response that plugin was installed correctly)
modified my index.html to call vibrate when the device is loaded
function onDeviceReady() {
navigator.notification.vibrate(2000);
}
But i still cant get the phonegap api to work since i get the error the method is not defined. Anybody got a solution for this or am i just plain dumb.
Regards
I would double check that you have installed both notification plugins:
cordova plugin add org.apache.cordova.dialogs
cordova plugin add org.apache.cordova.vibration
AND make sure that after you install the plugins you run the build command again:
phonegap local build android
Before deploying my code to native platforms, I often don't include links to the cordova.js and cordova_plugins.js. Make sure you've added those in before you prepare your code. It's an easy step to miss.
I installed phonegap 3.3.0 via the command line, created app, added android platform OK. I can use the latest Android ADT to import phonegap app and test it on my Android device. Everything worked perfect.
I installed the Email Composer plugin https://github.com/katzer/cordova-plugin-email-composer via the command line
cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
The plugin seems install ok, however when I tried to run the javascript code
window.plugin.email.open();
I got error
Uncaught TypeError: Cannot call method 'open' of undefined:43
I put the email_composer.js inside js folder and in my index.html I add reference to it. Not sure why I get this error.
I already asked the author here https://github.com/katzer/cordova-plugin-email-composer/issues/9 and he answered:
You lead the plugin in the wrong way. Do not lead the plugins directly.
If you install a plugin through the command line interface,
they will be listed in the cordova_plugins.js file which is loaded
by cordova.js.
I looked up the file cordova_plugins.js I only saw these code:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [];
module.exports.metadata =
// TOP OF METADATA
{}
// BOTTOM OF METADATA
});
I should see something about email_composer.js in this file, right? If so, then what I should write in here.
This is my first time using phonegap plugin, not sure what to do. Hope someone can help
Thanks
Always remember to 'prepare' your app after installing any new plugin. From the app's root:
cordova prepare android
This should update your cordova_plugins.js file
I found the bug. I got error if I call the javascript like this
window.plugin.email.open();
To make it works, call like this:
window.plugin.open();
(remove "email")
Hope this help someone