Search code examples
androidcordovaionic-frameworkpluginsionic4

Ionic - Failed to fetch plugin via registry


I want to add an alarm to my application.

I have tried to install cordova plugin add https://github.com/wnyc/cordova-plugin-wakeuptimer.git in to my project.

When I run command I get:

Failed to fetch plugin https://github.com/wnyc/cordova-plugin-wakeuptimer.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.

enter image description here

Ionic Info:

Ionic:

Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.1.1
@angular-devkit/build-angular : 0.901.7
@angular-devkit/schematics : 9.1.7
@angular/cli : 9.1.7
@ionic/angular-toolkit : 2.2.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, ios 5.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 4 other plugins)

Utility:

cordova-res : 0.9.0
native-run : 0.3.0

System:

Android SDK Tools : 26.1.1
NodeJS : v12.14.1
npm : 6.13.4
OS : Windows 10


Solution

  • Error is solved by following the below steps :

    1. Download repository source code
    If the plugin is hosted on Github, you can clone it into a local folder on your computer using git e.g (in this example will be cloned into C:/Users/Me/Desktop):

    git clone https://github.com/wnyc/cordova-plugin-wakeuptimer.git    
    

    In the clone directory, it should be now (once finished) a new folder with the name of the cloned repository.

    2. Create the package.json file
    To create a new package file for the plugin, you will obviously use Node.js in the command line and execute the following command (once located with the terminal in the folder of plugin):

    npm init
    

    This command will start an interactive prompt (that you can simply skip by pressing Enter on every question) that will allow you to create your package.json file. Obviously, although isn't necessary, you should provide correctly all the information

    3. Install it from the local source
    As the final step, you can install the plugin from the cloned repository but instead of providing the git URL, provide the local path to the plugin:

    cd FolderOfYourCordovaProject //Where you want to add a plugin
    
    cordova plugin add F:\WorkSpace\cordova-plugin-wakeuptimer 
    

    When I am adding plugin in my project It throws an error

    Invalid Plugin! C:\Users\Me needs a valid package.json

    Then I copied that plugin into the same disk/ same folder where the project is located.
    Then this error is also solved. And plugin added successfully.