Search code examples
angularionic-frameworkcordova-pluginsionic-native

Cannot find module '@ionic-native/camera-preview/ngx'


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?


Solution

  • 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.