Home > other >  Cordova nodejs integration for android
Cordova nodejs integration for android

Time:12-05

I am building a cordova app, and using a couple of nodejs modules in it. When application is deployed to android device, I am getting:

I chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: require is not defined", source: file:///android_asset/www/js/index.js (1)

The issue is caused by modules using x = require('z'), which does not work in browser window. On electron platform this issue is resolved by using nodeIntegration . But I can not find any documentation how to enable similar integration on android. Help?

CodePudding user response:

You cannot use nodejs modules with Cordova, you cannot embed nodejs within Cordova. It's different for a desktop app via Electron because you can install nodejs on a desktop, unlike a mobile phone.

CodePudding user response:

Cordova runs JavaScript by utilizing a WebView provided by the mobile phone. So you are restricted to the capabilities of the WebView (basically a slimmed down browser) and the native integrations that Cordova provides. You can read more here.

Electron on the other hand uses chromium and nodejs to run javascript. So you have access to browser as well as nodejs apis.

  • Related