0
votes

I am trying to install and use camera-preview from Ionic Native in the same way as I did for the other plugin camera. While it works for camera, I seem not to be able to redo the same for camera-preview.

I installed it as follows:

ionic cordova plugin add cordova-plugin-camera-preview
npm install --save @ionic-native/camera-preview

And then integrated it in my code as follow:

app.module.ts

import { CameraPreview } from '@ionic-native/camera-preview/ngx';

// ...

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    CameraPreview,
  ],
  bootstrap: [AppComponent]
})

home.page.ts

import { CameraPreview } from '@ionic-native/camera-preview/ngx';

// ...

export class HomePage {

  public image = '';

  constructor(private cameraPreview: CameraPreview) {

  }


}

When running ionic serve -c I receive the errors:

[ng] ERROR in src/app/app.module.ts(12,31): error TS2307: Cannot find module '@ionic-native/camera-preview/ngx'.

[ng] src/app/home/home.page.ts(2,31): error TS2307: Cannot find module '@ionic-native/camera-preview/ngx'.

What is going on?

2
which Ionic version you have?Sergey Rudenko
How can you check that?JohnAndrews
can u share your package.json and ionic info result?Sergey Rudenko
@JohnAndrews you can check with following command in terminal "ionic version"MD Khali

2 Answers

1
votes

I removed ngx from the plugin like:

from:

import { CameraPreview } from '@ionic-native/camera-preview/ngx';

to:

import { CameraPreview } from '@ionic-native/camera-preview';

and it solved the problem.

0
votes

Your code is fine, make sure you have the latest version of Ionic and Ionic-Native installed. Ionic 3 and early versions of 4 don't work with the ngx imports.

If you are on a later version (4.x or 5), then clean your node_modules folder and reinstall everything, including the camera plugin.