Ionic-native Cannot find module "ionic-native"


#1

Hi guys

I’ve been trying a lot of thing to get the native camera to work.
I am following the a Udemy tutorial by maximilian. he uses “import { Camera } from ‘ionic-native’;” to import the camera functionality.
However when I follow his steps, I get a runtime error saying “Cannot find module “ionic-native””.

I have tried “import { Camera } from ‘@ionic-native/camera’;” as stated in the docs.
However then I get an error in VS Code stating “[ts] Property ‘getPicture’ does not exist on type ‘typeof Camera’.”.

Any ideas what I might be doing wrong?


#2

Seems the Udemy tutorial is outdated.

This is code for Ionic Native 2.x.

This is code for Ionic Native 3.x.

You have to decide which one to use.


#3

Hi @kimdt27

For using camera in your application please use below mention code:
And I am guessing this two module install by you


$ ionic plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera
import { Component } from '@angular/core';
import { NavController} from 'ionic-angular';
import { Camera } from '@ionic-native/camera';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
    providers: [[Camera]]
})
export class HomePage {
  options:any;
  constructor(public navCtrl: NavController,private camera: Camera) { 
    this.takePicture();
  }
  
    public takePicture(){
      this.options = {
        quality: 100,
        sourceType: this.camera.PictureSourceType.CAMERA,
        saveToPhotoAlbum: true,
        correctOrientation: true,
        destinationType: this.camera.DestinationType.DATA_URL,
        mediaType: this.camera.MediaType.VIDEO
      }
      this.camera.getPicture(this.options)
        .then((imageData)=>{
            
        }).then((path) => {

        })
    }
}

Hope this will solve your issue.

Feel free to mark it as a solution and you can always like the answer by clicking heart icon.


#4

Thanks a lot, that did the trick!


#5

Okay. Yes, it seems like the tutorial is outdated.
Thanks for your input, I will continue working in 3.x


#6

A post was split to a new topic: Camera Plugin: Property ‘takePicture’ does not exist on type ‘Camera’