J.Rem
J.Rem

Reputation: 543

Property 'moveFile' does not exist on type 'typeof File' ionic typescript

Not sure what is wrong but when I try to use File from @ionic-native I receive the error "Property 'moveFile' does not exist on type 'typeof File'". The package son was added after asked in the comments

import { NavController } from 'ionic-angular';
import { ToastController } from 'ionic-angular';
import { File } from '@ionic-native/file';
import { Diagnostic } from '@ionic-native/Diagnostic';
import { CameraPreview } from 'ionic-native'
import { CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';
declare var cordova: any; 

constructor(public navCtrl: NavController, public toastCtrl: ToastController) {
  //  this.checkPermissions();
  }
  fileName = fileName.split("/").pop();
    File.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ => {
    this.toastCtrl.create(

package.json as requested from comments

{
  "name": "ionic-hello-world",
  "version": "0.0.0",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.0.2",
    "@angular/compiler": "4.0.2",
    "@angular/compiler-cli": "4.0.2",
    "@angular/core": "4.0.2",
    "@angular/forms": "4.0.2",
    "@angular/http": "4.0.2",
    "@angular/platform-browser": "4.0.2",
    "@angular/platform-browser-dynamic": "4.0.2",
    "@ionic-native/camera": "^3.6.0",
    "@ionic-native/camera-preview": "^3.6.0",
    "@ionic-native/core": "^3.6.1",
    "@ionic-native/diagnostic": "^3.6.1",
    "@ionic-native/file": "^3.6.1",
    "@ionic-native/splash-screen": "3.4.2",
    "@ionic-native/status-bar": "3.4.2",
    "@ionic/storage": "2.0.1",
    "ionic-angular": "3.1.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "^0.8.5"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.6",
    "typescript": "~2.2.1"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-statusbar",
    "cordova-plugin-console",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [
    "ios",
   {
      "platform": "ios",
      "version": "",
      "locator": "ios"
    }
   ],    
  "description": "camera-app: An Ionic project"
}

Upvotes: 2

Views: 1936

Answers (1)

Suraj Rao
Suraj Rao

Reputation: 29625

You are using ionic-native 3.x.

You need to inject File in constructor and use the object. Static functions from class existed in ionic-native 2.x.

constructor(public navCtrl: NavController, public toastCtrl: ToastController,
     public file:File) {
  //  this.checkPermissions();
  }
  fileName = fileName.split("/").pop();
    this.file.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ => {
    this.toastCtrl.create(

You also need to set File as a provider in app.module.ts.

@NgModule({
 //..
 providers: [..,File,..]
  })

Upvotes: 3

Related Questions