cordova-plugin-crypt-file-requireCordovaModule错误

时间:2019-03-24 17:49:25

标签: cordova module require

我只是将Cordova升级到版本9。它阻止了cordova-plugin-crypt-file插件停止工作-构建应用程序时出现错误

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.

问题似乎出在文件hooks / after_prepare.js。代码是

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; 

因此,我将所有context.requireCordovaModule更改为简单的require。它将产生新的错误消息:

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

请,有人可以帮我解决问题吗?还是有其他替代插件?

3 个答案:

答案 0 :(得分:3)

我有同样的问题。您需要将cordova降级到版本8.1.2

npm uninstall -g cordova
npm cache clean --force
npm i -g cordova@8.1.2

答案 1 :(得分:1)

请使用以下插件:

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

它基于cordova-plugin-crypt-file

上面的插件是与cordova-plugin-ionic-webview一起使用的,我已经更新了插件,现在它可以与cordova 9一起使用,因此不需要降级。

要安装它,请执行以下操作:

npm i cordova-plugin-crypto-file@latest

最新版本1.4.0修复了cordova 9问题。

答案 2 :(得分:0)

此修复程序对我在Cordova 9.0(cordova-ios)上有效:

在文件中:

  

cordova-plugin-crypt-file / hooks / after_prepare.js

,替换:

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; 

具有:

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

然后删除平台,然后再次重新添加。