# File.dataDirectory static in ionic-native can not be found by typescript

**URL:** <https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200>\
**Category:** ionic-v3\
**Created:** [March 16, 2017, 5:39pm UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200 "2017-03-16T17:39:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andmar8](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/andmar8/32/116756_2.png) [@andmar8](https://forum.ionicframework.com/u/andmar8)\
**Post date:** [March 16, 2017, 5:39pm UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200/1 "2017-03-16T17:39:01Z")

</div>

I’ve got this exact problem, as experienced by the OP very recently:

> <https://stackoverflow.com/questions/42744812/file-datadirectory-not-working-in-ionic-2>

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…

> <https://stackoverflow.com/questions/38276072/ionic-2-file-plugin-usage-examples>

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](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???

```auto
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:

```auto
Property 'dataDirectory' does not exist on type 'typeof File'.

```

---

<div class="post-metadata">

**Author:** ![andmar8](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/andmar8/32/116756_2.png) [@andmar8](https://forum.ionicframework.com/u/andmar8)\
**Post date:** [March 16, 2017, 6:24pm UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200/2 "2017-03-16T18:24:18Z")

</div>

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](https://github.com/driftyco/ionic-native) then run (in the project directory) a:

```auto
npm install

```

then:

```auto
npm run build

```

then as per the documentation: [https://github.com/driftyco/ionic-native/blob/master/DEVELOPER.md](https://github.com/driftyco/ionic-native/blob/master/DEVELOPER.md)

```auto
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

---

<div class="post-metadata">

**Author:** ![willyguevara](https://avatars.discourse-cdn.com/v4/letter/w/45deac/32.png) [@willyguevara](https://forum.ionicframework.com/u/willyguevara)\
**Post date:** [March 19, 2017, 6:39am UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200/3 "2017-03-19T06:39:40Z")

</div>

thanks, this works fine for me, **cheers**!

---

<div class="post-metadata">

**Author:** ![avishai\_peretz\_dev](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@avishai\_peretz\_dev](https://forum.ionicframework.com/u/avishai_peretz_dev)\
**Post date:** [March 20, 2017, 11:51am UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200/4 "2017-03-20T11:51:09Z")

</div>

> [@andmar8](#):
>
> ionic-native 2.8.1 (latest) “does” work

ionic-native 2.8.1 (latest) “does” work THANKS

---

<div class="post-metadata">

**Author:** ![andmar8](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/andmar8/32/116756_2.png) [@andmar8](https://forum.ionicframework.com/u/andmar8)\
**Post date:** [July 11, 2017, 10:04am UTC](https://forum.ionicframework.com/t/file-datadirectory-static-in-ionic-native-can-not-be-found-by-typescript/83200/5 "2017-07-11T10:04:04Z")

</div>

I have since discovered the even more “correct” way of doing this is to change your project’s package.json to update the entry

```auto
    "ionic-native": "2.4.1"

```

to

```auto
    "ionic-native": "2.8.1"

```

or

```auto
    "ionic-native": "2.9.0"

```

and run

```auto
npm install

```

or

```auto
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/](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

```auto
"@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 😡
