Search code examples
cordovamodulerequire

cordova-plugin-crypt-file - requireCordovaModule error


I just upgrade Cordova to version 9. It cased plugin cordova-plugin-crypt-file to stop working - when I build the application, I get error

Using "requireCordovaModule" to load non-cordova module "path" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.

It looks like the issue is with file hooks/after_prepare.js. The code is

var path              = context.requireCordovaModule('path'),
        fs                = context.requireCordovaModule('fs'),
        crypto            = context.requireCordovaModule('crypto'),
        Q                 = context.requireCordovaModule('q'),
        cordova_util      = context.requireCordovaModule('cordova-lib/src/cordova/util'),
        platforms         = context.requireCordovaModule('cordova-lib/src/platforms/platforms'),
        Parser            = context.requireCordovaModule('cordova-lib/src/cordova/metadata/parser'),
        ParserHelper      = context.requireCordovaModule('cordova-lib/src/cordova/metadata/parserhelper/ParserHelper'),
        ConfigParser      = context.requireCordovaModule('cordova-common').ConfigParser; 

So I changed all context.requireCordovaModule to simple require. It produces new error message:

Cannot find module 'cordova-lib/src/cordova/util'

Please, could anybody help me with fix? Or, is there any alternative plugin?


Solution

  • Please use the following plugin:

    https://github.com/PeterHdd/cordova-plugin-crypto-file

    It is based on the cordova-plugin-crypt-file.

    The above plugin was made to work with cordova-plugin-ionic-webview, I have updated the plugin and now it works with cordova 9, so there is no need to downgrade.

    To install it do the following:

    npm i cordova-plugin-crypto-file@latest
    

    latest version 1.4.0 fixes the cordova 9 issue.