Install Cordova plugin without package.json file on it

后端 未结 3 1272
情话喂你
情话喂你 2021-01-18 09:58

I\'m trying to install a Cordova Plugin with Cordova CLI 7.

This plugin does not have a package.json file on it, so it throws an error when adding it to my project.<

相关标签:
3条回答
  • 2021-01-18 10:20

    Yes, since Cordova 7, the installation of platforms and plugins are by default performed using cordova-fetch which in turn uses npm install to add/remove modules. Therefore a package.json is required by default. But you should be able to add plugins lacking a package.json file by using the nofetch parameter, which forces Cordova to use the old method instead, please note that this parameter has been removed in cordova 8.0.0:

    cordova plugin add cordova-plugin-camera --nofetch

    0 讨论(0)
  • 2021-01-18 10:20

    For me when adding a custom plugin like so

    cordova plugin add .\custom-plugins\my-plugin --nofetch
    

    This does not work on MAC for me for some reason.

    I resort to building it all for Android then copy over all the files, except node_modules and platforms, then do a 'cordova build ios' it seems to build fine with the custom plugins included. Not the best way i know, but once the plugin is added i can move on and continue. If you get it to work please share.

    0 讨论(0)
  • 2021-01-18 10:28

    --nofetch option is removed in Cordova 8.0.0: https://issues.apache.org/jira/browse/CB-13055

    If you have already installed Cordova 8.x.x then you can downgrade it to version 7.1.0 and then use the --nofetch option.

    Run the following command to downgrade Cordova to 7.1.0:

    npm install -g cordova@7.1.0
    

    If the above command doesn't work, then try uninstalling cordova at first and then install cordova version 7.1.0:

    npm uninstall -g cordova
    npm install -g cordova@7.1.0
    

    Then, check the Cordova version:

    cordova --version
    
    0 讨论(0)
提交回复
热议问题