在cordova中使用node模块

using node module in cordova

本文关键字:node 模块 cordova      更新时间:2023-09-26

我正在一个节点模块上工作,我想在Cordova中使用。我使用的语法是

 myModule.prototype.myMethod = function(){};
 module.exports = new myModule();

但我得到一个"模块未定义"错误。

这是一个可能的解决方案

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined'){
    module.exports = new myModule();
} else{
    window.myModule = new myModule();
}