116

Somehow in my app many of the cordova plugins are installed and because of that it requires access to almost everything - from my contacts to current location ( even though this app doesn't need this ).

This app is build via jenkins and as far as I understand one solution is to remove every plugin with single command, so it will be like:

cordova plugin rm org.apache.cordova.battery-status
cordova plugin rm org.apache.cordova.camera
cordova plugin rm org.apache.cordova.contacts
cordova plugin rm org.apache.cordova.geolocation
cordova plugin rm org.apache.cordova.media
cordova plugin rm org.apache.cordova.media-capture
cordova plugin rm org.apache.cordova.splashscreen
cordova plugin rm org.apache.cordova.vibration

But sometimes it shows some errors and with jenkins any error ends up with build failure, so is there any command which deletes all plugins? ( during installation basics plugins which requires any app to work are added automatically via cordova, so I was looking for some cordova plugin rm -all but couldn't find it )

mmmm
  • 3,768
  • 9
  • 36
  • 63
  • 1
    Y would recomment building a shell script that calls cordovaplugin list and then does cordova plugin rm for each line returned – QuickFix Feb 21 '14 at 11:42
  • I can only do something like that through makefile. And also I'm not that good with unix command line. – mmmm Feb 21 '14 at 12:07
  • you can try to fill a request in the cordova project to ask them to add a command to remove all plugins... – QuickFix Feb 21 '14 at 13:23
  • yeah, well I don't that much time to wait till they add a new command just for me.. – mmmm Feb 21 '14 at 13:24

15 Answers15

275

First, you should list your plugins:

cordova plugin list

With this result, you can simply do:

cordova plugin remove <PLUGIN_NAME>

For example:

cordova plugin remove org.apache.cordova.media
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
ruhanbidart
  • 4,564
  • 1
  • 26
  • 13
  • For some reason my VS2013 project does not list any and remove does not work. Gone to old fashion config.xml editing and plugin folder deletes... – Anthony Horne Sep 22 '15 at 11:35
  • 8
    The guy asked for a command to delete all at a time. This is a simple documented answer to remove only one at a time. – Imon Jan 25 '16 at 05:15
  • 8
    better to do `cordova plugin remove --save` so that it's automatically removed from config.xml – kamayd Jan 02 '17 at 19:36
21

You can do it with bash as well (after switching to your Cordova project directory):

for i in `cordova plugin ls | grep '^[^ ]*' -o`; do cordova plugin rm $i; done
JVE999
  • 3,327
  • 10
  • 54
  • 89
14

From the terminal (osx) I usually use

cordova plugin -l | xargs cordova plugins rm

Pipe, pipe everything!

To expand a bit: this command will loop through the results of cordova plugin -l and feed it to cordova plugins rm.

xargs is one of those commands that you wonder why you didn't know about before. See this tut.

kuzyn
  • 1,905
  • 18
  • 30
  • 1
    As of cordova 9.0.0 this no longer works correctly, JVE999's does work. – Bala Clark Apr 16 '19 at 14:54
  • Not working as I expected but it is better than to write the name of all those plugins. I had to run the command as many times as there were plugins. One time for each plugin but it is always the same command so I just pressed the up arrow and clicked enter multiple times. Thanks for the fix ;) – Inês Borges Jun 22 '22 at 14:13
11

You could use: cordova plugins list | awk '{print $1}' | xargs cordova plugins rm

and use cordova plugins list to verify if plugins are all removed.

Hamid Tavakoli
  • 4,567
  • 1
  • 33
  • 34
  • Didn't work. Get the following error: `Error: Plugin "{}" is not present in the project. See \`cordova plugin list\`` – tim-montague May 21 '17 at 06:16
  • 1
    @tfmontague try manually doing `cordova plugins ls` and then see if you can remove plugins one by one using `cordova plugins rm plugin_name`. From the error, it looks like one of the plugins are not physically present in your project. Using this method you can find that plugin. – Hamid Tavakoli May 23 '17 at 15:38
10

v2.0.0 of cordova-check-plugins enables you to remove all plugins in a project:

$ npm install -g cordova-check-plugins
$ cordova-check-plugins --remove-all

It will attempt to use the Cordova CLI to remove each plugin, but if this fails it will force removal of the plugin from platforms/ and plugins/.

If you also want to remove from config.xml, use:

$ cordova-check-plugins --remove-all --save

Disclaimer: I am the author of cordova-check-plugins

DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • $cordova-check-plugins --remove-all --save Removing all plugins... -FATAL ERROR: Failed to find local/global cordova or global phonegap CLI command when listing installed plugins - ensure you have cordova npm module installed either locally in your project folder or globally. Error: Command failed: phonegap -v 'phonegap' is not recognized as an internal or external command, operable program or batch file. – Naga Mar 28 '18 at 07:32
  • @Naga you need cordova or phonegap installed in your global npm directory which is specified by the default prefix npm config variable or whatever you set it to in your .npmrc/npmrc files. Most likely, yours is in `C:\Users\yourusername\AppData\Roaming\npm` if you are running on Windows or `/usr/local` on UNIX kernel. You can find out what your prefix is by typing in terminal/command `npm config get prefix` – rolling_codes May 25 '18 at 13:49
4

I do it with this python one-liner:

python -c "import subprocess as sp;[sp.call('cordova plugin rm ' + p.split()[0], shell=True) for p in sp.check_output('cordova plugin', shell=True).split('\n') if p]"

Obviously it doesn't handle any sort of error conditions, but it gets the job done.

Matthew Purdon
  • 754
  • 11
  • 28
  • 1
    Just use a shell script. Throwing yet another programming language with it's own dependencies into the mix makes Cordova an even bigger mess. – tim-montague May 21 '17 at 06:58
4
cordova platform rm android

cordova plugin rm cordova-plugin-firebase

cordova platform add android
double-beep
  • 5,031
  • 17
  • 33
  • 41
user9972736
  • 121
  • 1
  • 2
3

As far as I remember from Cordova, you should have an xml file in "res" folder containing the list of plugins used in your project. You probably need to remove those unused plugins from list. And also you should remove related files.

osayilgan
  • 5,873
  • 7
  • 47
  • 68
2

This is the commandline for removing plugins in Cordova

cordova plugin remove <pluginid>

For example I ran cordova plugin and got a list of plugins then I used the id for the plugin to uninstall

cordova plugin remove com.monday.contact-chooser

You can get help in the commandline by typing

cordova help <command>

Jack Shultz
  • 2,031
  • 2
  • 30
  • 53
  • cordova plugin remove com.monday.contact-chooser giving error as - Error: Plugin "cordova-plugin-name" is not present in the project. See `cordova plugin list`. – S.Yadav Jan 03 '17 at 06:25
  • 1
    Please remove your post, the question that was asked was "is there any command which deletes all plugins". – tim-montague May 21 '17 at 06:48
1

Scripts based on processing the list of installed plugins may not work as there are dependencies between installed plugins (e,g, cordova-plugin-file and cordova-plugin-file-transfer).

In the example, the script will find the file plugin first, then it will try to remove it and we'll get an error as file-transfer requires it. Therefore, we shall have

Nacho Marín
  • 71
  • 1
  • 2
  • This is a good point about dependencies between installed plugins. I think there's a force flag `--force`, which would remove the plugin regardless... – tim-montague May 21 '17 at 06:44
0

When running the command: cordova plugin remove <PLUGIN NAME>, ensure that you do not add the version number to the plugin name. Just plain plugin name, for example:

cordova plugin remove cordova.plugin_name 

and not:

cordova plugin remove cordova.plugin_name 0.01 

or

cordova plugin remove "cordova.plugin_name 0.01"

In case there is a privilege issue, run with sudo if you are on a *nix system, for example:

sudo cordova plugin remove cordova.plugin_name

Then you may add --save to remove it from the config.xml file. For example:

cordova plugin remove cordova.plugin_name --save
Olu Adeyemo
  • 825
  • 9
  • 17
0
  • access the folder
  • list the plugins (cordova plugin list)
  • ionic cordova plugin remove "pluginName"

Should be fine!

Mekkush
  • 5
  • 4
0

If the above solution didn't work and you got any unhandled promise rejection then try to follow steps :

  1. Clean the Cordova project

    cordova clean

    1. Remove platform

cordova platform remove android/ios

  1. Then remove plugin

cordova plugin remove

  1. add platforms and run the project It worked for me.
rahul.sapkal23
  • 707
  • 9
  • 15
0

This is somewhat related and might help others, I had a corrupt version of some of my plugins so I was able to just delete the entire contents of the plugins folder. Note, all references are still in the package.json and config.xml files to the plugins. So then when I removed and added the Android platform, it re-installed the uncorrupted versions of the plugins and fixed my problem.

Nathan Prather
  • 2,098
  • 1
  • 18
  • 15
0

I am probably late, however there is a way...

Firstly, unfortunately there is no cordova plugin rm all, but we can work around it.

Just remove plugins dir and then re add all the plugins u need. But be ware this is not 'official' way to do it, but it works on both Android and iOS. I have just tested it, because I needed similar scripts for platform specific.

If u find it helpful consider pinning this response if possible.

Regards ;)

TheToster
  • 7
  • 1
  • 1