Cannot find name 'ScreenOrientation'. Error in ionic screen orientation plugin - ionic-framework

I am creating an app using ionic version 4 using Angular 6! I need to get the orientation if device so i used screen orientation plugin from Ionic 4 docs:
[https://beta.ionicframework.com/docs/native/screen-orientation]
But when I installed the plugin I got the warnings as :
.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic/ng-toolkit#1.0.8 requires a peer of #angular-devkit/build-angular#~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic/ng-toolkit#1.0.8 requires a peer of #angular-devkit/core#~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic/ng-toolkit#1.0.8 requires a peer of #angular-devkit/schematics#~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic/schematics-angular#1.0.6 requires a peer of #angular-devkit/core#~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic/schematics-angular#1.0.6 requires a peer of #angular-devkit/schematics#~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic-native/screen-orientation#4.12.2 requires a peer of #ionic-native/core#^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic-native/screen-orientation#4.12.2 requires a peer of rxjs#^5.5.11 but none is installed. You must install peer dependencies yourself.
+ #ionic-native/screen-orientation#4.12.2
added 1 package in 8.608s
Now when I tried to import in a page like:
Failed to compile.
./node_modules/#ionic-native/screen-orientation/index.js Module not
found: Error: Can't resolve 'rxjs/Observable' in
'/Users/karthikcp/Documents/IONIC/testbake/node_modules/#ionic-native/screen-orientation'
How could I solve this?
Informations:
```
Ionic:
ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : #ionic/angular 4.0.0-beta.7
#angular-devkit/core : 0.7.5
#angular-devkit/schematics : 0.7.5
#angular/cli : 6.1.5
#ionic/ng-toolkit : 1.0.8
#ionic/schematics-angular : 1.0.6
Cordova:
cordova (Cordova CLI) : 7.1.0
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (2 plugins total)
System:
ios-deploy : 1.9.2
NodeJS : v8.11.3 (/Users/karthikcp/.nvm/versions/node/v8.11.3/bin/node)
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Update
I reinstalled the plugin as : npm install --save #ionic-native/screen-orientation#5.0.0-beta.15
Now I am getting this error :
ERROR in src/app/pages/test/test.page.ts(14,42): error TS2304: Cannot find name 'ScreenOrientation'.
Dependencies:
"dependencies": {
"#angular/common": "~6.1.1",
"#angular/core": "~6.1.1",
"#angular/forms": "~6.1.1",
"#angular/http": "~6.1.1",
"#angular/platform-browser": "~6.1.1",
"#angular/platform-browser-dynamic": "~6.1.1",
"#angular/router": "~6.1.1",
"#ionic-native/core": "5.0.0-beta.15",
"#ionic-native/screen-orientation": "^5.0.0-beta.15",
"#ionic-native/splash-screen": "5.0.0-beta.15",
"#ionic-native/status-bar": "5.0.0-beta.15",
"#ionic/angular": "4.0.0-beta.7",
"cordova-plugin-screen-orientation": "^3.0.1",
"core-js": "^2.5.3",
"rxjs": "6.2.2",
"zone.js": "^0.8.26"
},

I only get this error, if i'm importing like this:
import { ScreenOrientation } from '#ionic-native/screen-orientation';
but if i'm adding /ngx to #ionic-native/screen-orientation than it doesn't show the cannot find name Error.
But on my side it show's
NullInjectorError: No Provider for ScreenOrientation!
Maybe that work's as wanted if you add /ngx.

This worked for me. Inside your page.module, import dependency:
import { ScreenOrientation } from '#ionic-native/screen-orientation/ngx';
and provide to the module:
providers: [
ScreenOrientation,
...]
Be careful, if not expecified 'ScreenOrientation' from an expecific import, it will take a typescript interface. That was my mistake.

Related

Updating ionic with command?

I just installed ionic CLI#5.4.4. It is latest version.
But When I started new project it installed "#ionic/angular": "^4.7.1", "#angular/core": "~8.1.2" and so on. So not latest versions :/
How should I update those?
ng update #ionic/angular #angular/core #angular/cli ?
Or maybe simply update package.json file?
You can also just modify your package.json and run npm install.

livereload doesn't give choice of addresses

After the updation of node.js i found this issue.. when i run ionic cordova run android --livereload it is running in localhost
How do i solve this issue ?? please help me..
Ionic Info:
Ionic CLI : 5.2.1
Ionic Framework : #ionic/angular 4.6.0
#angular-devkit/build-angular : 0.13.9
#angular-devkit/schematics : 7.3.9
#angular/cli : 7.3.9
#ionic/angular-toolkit : 1.5.1
Cordova:
Cordova CLI : 9.0.0 (cordova-lib#9.0.1)
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 4 other plugins)
Utility:
cordova-res : not installed
native-run : 0.2.7
System:
NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.9.2
OS : Windows 10
So this is a new change in Ionic-cli v5.2.1
You can use this command
ionic serve --address=0.0.0.0
or in your case
ionic cordova run android --livereload --address=0.0.0.0
or if you have a specific url
ionic cordova run android --livereload-url=http://localhost:8100
This will spin up the server like it used to previously, both on the localhost as well as the external url.
See this update documentation for more info
https://ionicframework.com/docs/cli/commands/cordova-run

IONIC : A utility CLI has unexpectedly closed

I got this error when i run ionic serve
The Ionic CLI will exit. Please check any output above for error details.
my ionic info
$ionic info
Ionic:
ionic (Ionic CLI) : 4.0.1 (C:\Users\Pc\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
#ionic/app-scripts : 3.1.8
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
System:
Android SDK Tools : 25.3.1
NodeJS : v6.10.1 (C:\Program Files\nodejs\node.exe)
npm : 5.3.0
OS : Windows 10
Environment:
ANDROID_HOME : C:\Users\Pc\AppData\Local\Android\sdk
Run the below command, being in root directory of Ionic project:
npm install #ionic/app-scripts#latest --save-dev
Then you can try Ionic serve or Ionic s.
I had a similar issue:
Assertion `args[1]->IsString()' failed.
A utility CLI has unexpectedly closed
I fixed that by installing natives lib through npm:
npm i natives
Simpy run
npm install #ionic/app-scripts#latest --save-dev
and then
ionic serve
This error is because of some audit during installing a plugin or adding a plug in
I had a similar issue. I tried several different solutions, and for some reason different ones worked on different machines. Because I'm an illogical masochist, I attempted to fix this issue in the same project on 3 different laptops instead of sending the new fixed version to the other laptops.
The best answer I came up with is to:
Delete node_modules
copy node_modules from a different project (I used an earlier version of my app)
run npm i to install any missing modules
I think this approach should work for almost all instances.
You must kill the NodeJs service I believe it's a bug
Try replacing the package.json scripts parts. Worked for me.
"scripts": {
"build": "ionic build",
"serve": "ionic build",
"start": "npm run serve"
},
Try running:
npm install #ionic/lab
Maybe there is an issue in your hosts file. Make sure your ::1 should enable or not commented.
Example:
I don't know why but using sudo was the only way to solve this on my ubuntu machine!
I just needed to run the command using sudo:
sudo ionic serve
Error: Lock found, but no process with PID 43470 seems to be running.
[ng] (If you are sure no ngcc process is running then you should delete the lock-file at yourproject/node_modules/#angular/compiler-cli/ngcc/ngcc_lock_file.)
rm yourproject/node_modules/#angular/compiler-cli/ngcc/ngcc_lock_file
et voila.
if you get this in the log:
The target entry-point "#ionic-native/media-capture" has missing
dependencies:
#ionic-native/core
try this,
npm install --save #ionic-native/core
My solution:
Upgrade Angular. It'll reveal the real reason for unexpectedly closing in a more verbouse error message. Mine was incompatible dependencies. I simply edited package.json with the right depencies, and ran npm update
For any Linux Users: This error might occur if you installed node.js via the snapstore. Either change PATH to /usr/local/bin/node or use npm to update/install node.js again at the right place.

Failed to install phonegap-plugin-push

I am following Ionic Push setup guide but I am getting an error trying to install phonegap plugin:
cordova plugin add phonegap-plugin-push --variable SENDER_ID=123456789 --save --verbose
Im getting and error:
Error: Invalid Version: broken
this is ionic info --verbose generate following output:
[DEBUG] Loading global plugin #ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for global #ionic/cli-plugin- proxy
[DEBUG] Loading local plugin #ionic/cli-plugin-cordova
[DEBUG] Loading local plugin #ionic/cli-plugin-ionic-angular
global packages:
#ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
local packages:
#ionic/app-scripts : 1.1.4
#ionic/cli-plugin-cordova : 1.4.1
#ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android broken
Ionic Framework : ionic-angular 2.2.0
System:
Node : v6.9.1
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.8
Can anybody point me in the right direction?
Follow this link ::
https://github.com/phonegap/phonegap-plugin-push
Try to install plugin using this command
cordova plugin add https://github.com/phonegap/phonegap-plugin-push

An error occurred while running cordova plugin add de.appplant.cordova.plugin.local-notification

While attempting to install the cordova plugins for local-notification for an Ionic Framework cross platform app I received the following:
Installing "de.appplant.cordova.plugin.local-notification" for android
Plugin dependency "cordova-plugin-device#1.1.4" already fetched, using
that version. Dependent plugin "cordova-plugin-device" already installed on android.
Failed to install 'de.appplant.cordova.plugin.local-notification': Error
at
/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:205:33
I've already tried the solution at https://github.com/katzer/cordova-plugin-local-notifications to no avail. All I'm trying to do is load the plugins as described on Ionic's site: https://ionicframework.com/docs/native/local-notifications/ and I they won't install the plugins.
$ ionic cordova plugin add de.appplant.cordova.plugin.local-notification
$ npm install --save #ionic-native/local-notifications
It is quite possible that you have Yarn installed, and that it is clashing with your version of NPM. Try removing Yarn, and your node_modules and re-installing.
For example, if you are using Brew, you could do the following:
# Uninstall Yarn
brew uninstall yarn
brew update
brew doctor
# Uprade Node & NPM
brew upgrade node
npm install -g npm#latest
Then in your project directory:
cd my-cordova-project
rm -rf node_modules
Check your package.json for broken links, for example: package dependancies with no version number that linger from installs that did not complete.
{
"name": "helloworld",
"displayName": "HelloCordova",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"dependencies": {
"cordova-android": "^6.2.3",
// FAILED INSTALL MIGHT CREATE EMPTY VERSION!
"cordova-plugin-app-version": ""
},
"cordova": {
"plugins": {
"de.appplant.cordova.plugin.local-notification": {},
"cordova-plugin-app-version": {}
}
}
}
Now install everything again with npm:
npm install
Here is my version info in case that helps you debug:
node --version
v8.1.4
npm --version
5.3.0
cordova --version
7.0.1