# Ioinic-nativ file plugin ReferenceError: documentsDirectory is not defined↵

**URL:** <https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368>\
**Category:** ionic-v3\
**Created:** [February 14, 2019, 7:00pm UTC](https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368 "2019-02-14T19:00:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![konipaka](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@konipaka](https://forum.ionicframework.com/u/konipaka)\
**Post date:** [February 14, 2019, 7:00pm UTC](https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368/1 "2019-02-14T19:00:07Z")

</div>

Hello  
Emulating my app for android and trying to store a pdf file with the cordova-file-plugin I get the error message:

> core.js:1449 ERROR TypeError: Object(…) is not a function  
> at File.get [as dataDirectory] (index.js:649)  
> at MergeMapSubscriber.project (euro-bus-test.ts:83)  
> The code:

```auto
  import {File} from '@ionic-native/file/ngx'; 
  
  constructor( public navCtrl: NavController,
                public navParams: NavParams, 
                public http: HttpClient,  
                private storage :Storage,
                private file: File) {
  }

private downloadFile(url:string, fileName : string): Observable<any> {
    return this.http.get(url, {responseType: 'blob'})
      .flatMap((data: Blob) => {
        return Observable.from(this.file.writeFile(this.file.dataDirectory, fileName, data, {replace: true}))
      })
  }

```

The error happens in this line of code:  
` this.file.writeFile(this.file.dataDirectory, fileName, data, {replace: true})`  
When I check the dataDirectory in the debugger it says:  
**ioinic-nativ file plugin ReferenceError: documentsDirectory is not defined**  
When I check **this.file.dataDirectory** it says: **TypeError: Object(…) is not a function**

The other point is, that the import only ‘works’, if I import from ‘file/ngx’ like in shown in the code. Without /ngx the imported ‘File’ is not used in the constructor, and the method writeFile() doesn’t exists (of course).This wasn’t nessecary yesterday.

---

<div class="post-metadata">

**Author:** ![anna\_liebt](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@anna\_liebt](https://forum.ionicframework.com/u/anna_liebt)\
**Post date:** [February 14, 2019, 8:01pm UTC](https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368/2 "2019-02-14T20:01:35Z")

</div>

Hello,  
maybe you updated package.json. Maybe you must go back from an ionic/native version 5.x.x to an older 4.x.x version.

Best regards, anna-liebt

---

<div class="post-metadata">

**Author:** ![konipaka](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@konipaka](https://forum.ionicframework.com/u/konipaka)\
**Post date:** [February 15, 2019, 12:34pm UTC](https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368/3 "2019-02-15T12:34:06Z")

</div>

Hello liebende Anna,  
I think you’re right. After moving back to a backup version it works.  
I made an update of ionic core due to a warnig I got during installing the file-plugin.  
Thanks

---

<div class="post-metadata">

**Author:** ![anna\_liebt](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@anna\_liebt](https://forum.ionicframework.com/u/anna_liebt)\
**Post date:** [February 15, 2019, 12:41pm UTC](https://forum.ionicframework.com/t/ioinic-nativ-file-plugin-referenceerror-documentsdirectory-is-not-defined/156368/4 "2019-02-15T12:41:24Z")

</div>

hello,  
it should be both possible. Make a backup of working package.json, then you need to update all native packages to version 5.x.x or you stay at 4.x.x and freeze this versions.  
How npm versions syntax is and how they update, is described here [https://flaviocopes.com/npm-semantic-versioning/](https://flaviocopes.com/npm-semantic-versioning/)

Best regards, anna-liebt
