I strangle to be able to catch this error.
While on desktop, this code raise this  NotSupportedError:

I normally debug on chrome.
Here is the code:
import {Component} from "@angular/core";
import {ScreenOrientation} from "@ionic-native/screen-orientation";
@IonicPage()
@Component({
  selector: 'page-loading',
  templateUrl: 'page-loading.html',
})
export class PageLoading {
  constructor(private screenOrientation:ScreenOrientation) {}
  ionViewDidLoad() {
    console.log('ionViewDidLoad PageLoading');
    try{
        this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT).then(()=>{
          console.log('lock');
        });
    }catch(e){
      console.warn('No cordova.js')
    }
  }
}
                You can create a class to mock ionic native classes as described in the docs here.
class ScreenOrientationMock extends ScreenOrientation {
  lock(type) {
    return new Promise((resolve, reject) => {
      resolve("locked");
    })
  }
}
In your providers list in ngModule mention it should use your mocked class instead of the actual ionic native one.
providers: [..
    { provide: ScreenOrientation, useClass: ScreenOrientationMock }
 ]
This will return whatever you have set in resolve for screenorientation during ionic serve. 
You can remove it once it is run in a device.
EDIT:
There is another possibility to suppress your error, so you will not have anything to do at the end:
if(this.platform.is('cordova')){
  this.platform.ready().then(()=>{
   this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
  })
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With