I’ve got this exact problem, as experienced by the OP very recently:
one suggestion on that SO posts suggests doing a npm@latest install, but that doesn’t work, what does “fix” it is using the cordova.file.XXXX underlying plugin code, but you have to declare cordova as a global var after your imports to satisfy typescript…
this is hugely hacky and the File class “does” specify a static correctly as can be seen here:
https://github.com/driftyco/ionic-native/blob/master/src/plugins/file.ts#L386
so why would using the code as per the example(!) not work???
import { File } from 'ionic-native';
const dataDirectory: string = File.dataDirectory;
File.checkDir(dataDirectory, 'mydir').then(_ => console.log('yay')).catch(err => console.log('boooh'));
the error you receive is:
Property 'dataDirectory' does not exist on type 'typeof File'.
1 Like
OK, it looks like the REAL answer is the version of file.js you get in the transpiled ionic-native bundled with ionic 2.2.1 does not “have” the static definitions
If you download the latest ionic-native code base from here: https://github.com/driftyco/ionic-native then run (in the project directory) a:
npm install
then:
npm run build
then as per the documentation: https://github.com/driftyco/ionic-native/blob/master/DEVELOPER.md
You need to run npm run build in the ionic-native project, this will create a dist directory. Then, you must go to your ionic application folder and replace your current node_modules/ionic-native/dist/ with the newly generated one
“THAT” truly works how it should (none of this nonsense with declaring a cordova var).
EDIT: yup, ionic 2.2.1 uses ionic-native 2.4.1 which doesn’t work, however, ionic-native 2.8.1 (latest) “does” work
2 Likes
thanks, this works fine for me, cheers!
ionic-native 2.8.1 (latest) “does” work THANKS
I have since discovered the even more “correct” way of doing this is to change your project’s package.json to update the entry
"ionic-native": "2.4.1"
to
"ionic-native": "2.8.1"
or
"ionic-native": "2.9.0"
and run
npm install
or
npm update
which “should” then update the ionic native package in the build.
Since then, ionic 3 has also come about using the even newer ionic-native 3 stuff (http://blog.ionic.io/ionic-native-3-x/), this would need you to entriely remove the old ionic-native package reference and replace it with
"@ionic-native/file": "3.12.1"
Basically, I’ve since discovered, the better way of solving this problem is to use npm to update your project… which is FANTASTICALLY poorly documented
2 Likes