Ionic 6: file(...) is undefined

I’m trying to use https://ionicframework.com/docs/native/file in ionic 6 with capacitor but I’m always getting the msg: TypeError:

this.objFile.writeFile(…) is undefined

Code:

app.module.ts

import { File } from '@awesome-cordova-plugins/file/ngx';

update.service.ts

import { File } from '@awesome-cordova-plugins/file/ngx';

constructor(private objHttp: HttpClient, private objAlertController: AlertController, private objFile: File) {
  }
  
  
  fileWrite(filename: string, content: string) {
    this.objFile.writeFile(this.currentFolder, filename, content).then(() => { //BUG
    }).catch(r => {
      console.error('r'); //todo: rm debug
    })
  }

package.json

"dependencies": {
    "@angular/common": "~13.0.0",
    "@angular/core": "~13.0.0",
    "@angular/forms": "~13.0.0",
    "@angular/platform-browser": "~13.0.0",
    "@angular/platform-browser-dynamic": "~13.0.0",
    "@angular/router": "~13.0.0",
    "@awesome-cordova-plugins/file": "^5.39.1",
    "@capacitor/android": "3.4.0",
    "@capacitor/app": "^1.1.0",
    "@capacitor/browser": "^1.0.7",
    "@capacitor/core": "3.4.0",
    "@capacitor/haptics": "^1.1.4",
    "@capacitor/keyboard": "^1.2.1",
    "@capacitor/share": "^1.1.1",
    "@capacitor/status-bar": "^1.0.7",
    "@capacitor/storage": "^1.2.4",
    "@ionic-native/app-rate": "^5.36.0",
    "@ionic-native/splash-screen": "^5.36.0",
    "@ionic-native/sqlite": "^5.36.0",
    "@ionic-native/text-to-speech": "^5.36.0",
    "@ionic/angular": "^6.0.0",
    "cordova-plugin-file": "^6.0.2",
    "cordova-sqlite-storage": "^6.0.0",
    "leaflet": "^1.7.1",
    "leaflet-ant-path": "^1.3.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.0.1",
    "@angular-eslint/builder": "~13.0.1",
    "@angular-eslint/eslint-plugin": "~13.0.1",
    "@angular-eslint/eslint-plugin-template": "~13.0.1",
    "@angular-eslint/template-parser": "~13.0.1",
    "@angular/cli": "~13.0.1",
    "@angular/compiler": "~13.0.0",
    "@angular/compiler-cli": "~13.0.0",
    "@angular/language-service": "~13.0.0",
    "@capacitor/cli": "3.4.0",
    "@ionic/angular-toolkit": "^5.0.0",
    "@ionic/lab": "3.2.10",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "typescript": "~4.4.4"
  },

I also tried capacitor native FileSystem and used it exactly like in some github repos I found but I always got the msg, that its use with const is deprecated and it didn’t worked anyway.

Can someone maybe help with this? I’m trying since 2 days. I just need to save and read files.

Hi !
Prefere capacitor Filesystem plugin. Capacitor - build cross platform apps with the web
Its work only on real device (not ionic serve) and don’t forget to add android permission

And try something like this

writeDocument(document: string, base64: string): Promise<string> {
        return new Promise((resolve, reject) => {
            const uri = await Filesystem.writeFile({
                path: `documents/${document}`,
                data: `${base64}`,
                directory: Directory.Data,
                recursive: true
            }).catch((err) => reject(err));
            if (uri) {
                resolve(uri.uri);
            }
        });
    }