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


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:

  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.


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


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.


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

Best regards, anna-liebt