Cordova.file is not working


#1

I’m calling cordova.file.dataDirectory and I keep getting the following error message:

TypeError: Cannot read property ‘dataDirectory’ of undefined

I’ve scoured Google for three hours looking for answers.

Here is a stack trace: https://gist.github.com/anonymous/a28b983f81f1899a49ca
Here is the code where I call it: https://gist.github.com/anonymous/8c0f30f1bf68f732b4a3
Here is the main app module (unmodified after ionic start cmd): https://gist.github.com/anonymous/d4becf3b4ea801f1d593

I only share the last file because I have found mentions on Google of putting the call inside ionicPlatform.ready() function but the tutorial I’m following does not do it that way.

Thank you.


#2

Did you install the Cordova file plugin? From the terminal in the root of your project:

ionic plugin add org.apache.cordova.file

#3

Wow, thank you. That worked. I had run “cordova plugin add org.apache.cordova.file”. I did not know that I had to use “ionic” instead of"cordova". Is that true for all plugins? Thank you.


#4

Yeah, I don’t know what the difference is, as I think the Ionic CLI is a wrapper for the Cordova CLI as far as plugins go. I just use the Ionic CLI all the time for consistency and just in case something is different - which it apparently is in this case.


#5

same problem here on ios 7.1.2

cordova.file is undefined on ios, on android its working!

Any ideas?
I used this plugin: cordova plugin add cordova-plugin-file

I’m out of ideas after six hours of searching the web …


#6

Did you guys fond a solution or workaround?

The same suddenly appeared on adnroid 4.4.4. The strange thing is that I can do console.log(cordova) and I see cordova.file which looks fine. But when I do console.log(cordova.file) one line below I get undefined.


#7

Hi all, a quick follow-up on ‘cordova plugin add’ vs. ‘ionic plugin add’. Ionic CLI indeed wraps some cordova methods, but it also extends/fixes some things on it, e.g. by adding the plugin to the package.json. This might be useful when using ‘ionic state reset’ as it will take the package.json as base for plugin installation.