ionic3问题之三插件安装失败问题

Posted by LuckXiang on May 29, 2018

按照官网的命令去安装的插件,排除名字错误这种低级错误,我遇到过好几次这种问题,比如我去安装全屏这个插件,

 ionic cordova plugin add cordova-plugin-fullscreen
 npm install --save @ionic-native/android-full-screen

两个命令都会报错,比如第一条命令的错误.会提示我找不到这个插件.

(node:27260) UnhandledPromiseRejectionWarning: CordovaError: Failed to fetch plugin cordova-plugin-fullscreen via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 254 Error output:
npm ERR! path /home/luckyxiang/Workspace/gitlab/nativeTransiton/node_modules/cordova-android/node_modules/cordova-common/node_modules/cordova-registry-mapper/node_modules/tape/node_modules/deep-equal
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/home/luckyxiang/Workspace/gitlab/nativeTransiton/node_modules/cordova-android/node_modules/cordova-common/node_modules/cordova-registry-mapper/node_modules/tape/node_modules/deep-equal' -> '/home/luckyxiang/Workspace/gitlab/nativeTransiton/node_modules/cordova-android/node_modules/cordova-common/node_modules/cordova-registry-mapper/node_modules/tape/node_modules/.deep-equal.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

经过分析我发现,出现这个问题的时候都是我我安装了指定版本的安卓ionic cordova platforms add android导致的,估计是包管理的问题,这样问题就好办了,先卸载安卓再安装插件

➜  nativeTransiton git:(master) ✗ ionic cordova platforms rm android
> cordova platform remove android --save
Removing platform android from config.xml file...

Removing android from cordova.platforms array in package.json



➜  nativeTransiton git:(master) ✗ ionic cordova plugin add cordova-plugin-fullscreen -        
> cordova plugin add cordova-plugin-fullscreen --save
Adding cordova-plugin-fullscreen to package.json

Saved plugin info for "cordova-plugin-fullscreen" to config.xml


➜  nativeTransiton git:(master) ✗ npm install --save @ionic-native/android-full-screen
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ @ionic-native/android-full-screen@4.7.0
added 1 package in 2.621s
➜  nativeTransiton git:(master) ✗ ionic cordova platforms add android@5.0.0           
> cordova platform add android@5.0.0 --save
Using cordova-fetch for cordova-android@5.0.0

Adding android project...
Creating Cordova project for the Android platform:
	Path: platforms/android
	Package: io.ionic.starter
	Name: nativeTransiton
	Activity: MainActivity
	Android target: android-23
Android project created with cordova-android@5.0.0
Installing "com.telerik.plugins.nativepagetransitions" for android
Installing "cordova-plugin-device" for android
Installing "cordova-plugin-fullscreen" for android
Installing "cordova-plugin-ionic-keyboard" for android
Installing "cordova-plugin-ionic-webview" for android
Installing "cordova-plugin-splashscreen" for android
Installing "cordova-plugin-statusbar" for android

Installing "cordova-plugin-whitelist" for android


               This plugin is only applicable for versions of cordova-android greater than 4.0. If you have a previous platform version, you do *not* need this plugin since the whitelist will be built in.
          
--save flag or autosave detected
Saving android@~5.0.0 into config.xml file ...