Ionic 2 native file not working

When i use ionic native file in ionic 2 found this error

Runtime Error Cannot find module "ionic-native/file" 

i followed this link

Error when i use ionic serve

Error
Close
Runtime Error
Cannot find module "ionic-native/file"
Stack
Error: Cannot find module "ionic-native/file"
    at d (http://localhost:8100/build/polyfills.js:3:3991)
    at Object.<anonymous> (http://localhost:8100/build/main.js:55595:7)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:74319:75)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:74078:73)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at Object.<anonymous> (http://localhost:8100/build/main.js:111182:70)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at http://localhost:8100/build/main.js:66:18
    at http://localhost:8100/build/main.js:69:10
Ionic Framework: 3.1.1
Ionic Native: ^3.5.0
Ionic App Scripts: 1.3.6
Angular Core: 4.0.2
Angular Compiler CLI: 4.0.2
Node: 6.10.2
OS Platform: Linux 4.8
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.81 Chrome/58.0.3029.81 Safari/537.36

Any one can solve this ? Thank you.

ts file

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {File} from 'ionic-native/file';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController,private file: File) {

  }
  open(){
 this.file.checkDir(this.file.dataDirectory, 'mydir').then(_ => console.log('Directory exists')).catch(err => console.log('Directory doesnt exist'));
  }

}

I believe you are missing an ampersand: @ionic-native/file.

Thank you For Your Reply.
When i use @ionic-native/file
getting this error
Error: Uncaught (in promise): Error: No provider for File!

Error: Uncaught (in promise): Error: No provider for File!
Error
    at d (http://localhost:8100/build/polyfills.js:3:3991)
    at injectionError (http://localhost:8100/build/main.js:1509:86)
    at noProviderError (http://localhost:8100/build/main.js:1547:12)
    at ReflectiveInjector_._throwOrNull (http://localhost:8100/build/main.js:3048:19)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:8100/build/main.js:3087:25)
    at ReflectiveInjector_._getByKey (http://localhost:8100/build/main.js:3019:25)
    at ReflectiveInjector_.get (http://localhost:8100/build/main.js:2888:21)
    at AppModuleInjector.NgModuleInjector.get (http://localhost:8100/build/main.js:3835:52)
    at resolveDep (http://localhost:8100/build/main.js:11208:45)
    at createClass (http://localhost:8100/build/main.js:11069:91)
    at createDirectiveInstance (http://localhost:8100/build/main.js:10905:37)
    at createViewNodes (http://localhost:8100/build/main.js:12255:49)
    at createRootView (http://localhost:8100/build/main.js:12160:5)
    at callWithDebugContext (http://localhost:8100/build/main.js:13291:42)
    at Object.debugCreateRootView [as createRootView] (http://localhost:8100/build/main.js:12752:12)
    at d (http://localhost:8100/build/polyfills.js:3:3991)
    at l (http://localhost:8100/build/polyfills.js:3:3244)
    at Object.reject (http://localhost:8100/build/polyfills.js:3:2600)
    at NavControllerBase._fireError (http://localhost:8100/build/main.js:43017:16)
    at NavControllerBase._failed (http://localhost:8100/build/main.js:43005:14)
    at http://localhost:8100/build/main.js:43060:59
    at t.invoke (http://localhost:8100/build/polyfills.js:3:11562)
    at Object.onInvoke (http://localhost:8100/build/main.js:4403:37)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:11502)
    at n.run (http://localhost:8100/build/polyfills.js:3:6468)
    at http://localhost:8100/build/polyfills.js:3:3767
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12256)
    at Object.onInvokeTask (http://localhost:8100/build/main.js:4394:37)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12177)
    at n.runTask (http://localhost:8100/build/polyfills.js:3:7153)
Ionic Framework: 3.1.1
Ionic Native: ^3.5.0
Ionic App Scripts: 1.3.6
Angular Core: 4.0.2
Angular Compiler CLI: 4.0.2
Node: 6.10.2
OS Platform: Linux 4.8
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.81 Chrome/58.0.3029.81 Safari/537.36

RTFM. You forgot to declare it in your app module.

1 Like

How can i declare this one in my app module.

Thank you so much for your answer … I got it thank you once again

i imported my app module this file

import {File} from '@ionic-native/file'

then i add the same page app module provider

  providers: [
    StatusBar,
    SplashScreen,
    File,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]

Thank you Now Working File.

1 Like

I want to upload a pdf file. How can i do this. I am using camera plugin that working only camera or gallery at same think i want to file .for example i open to upload Camera , Gallery , File . Now i did only camera and gallery . How to i do in file (PDF,Txt) uploading. If any way to do this one?

Step 1: Open a new topic where you describe this new request and problem.

1 Like