Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova error: Using "requireCordovaModule" to load non-cordova module "q" is not supported

I noticed that the builds on our CI started to fail because of the following error:

Discovered plugin "cordova-plugin-app-version" in config.xml. Adding it to the project

Installing "cordova-plugin-app-version" for android

Adding cordova-plugin-app-version to package.json
Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
[ERROR] Exception: 
The command '/bin/sh -c ionic cordova platforms add android' returned a non-zero code: 1

Same issue happens on both iOS and Android.

After some digging, I found that cordova 9.0.0 was recently released.

There are a couple of changes related to this issue.

  • GH-710 Drop Q Dependency and Use Native Promises
  • GH-707 Deprecate requireCordovaModule for non-Cordova modules

My first thought was that somehow we didn't have our cordova version locked, but we did lock it to [email protected] in our dockerfile. I also tested it on my local machine and I cordova version 8.1.2 as well. So this can't be the issue.

After looking at the logs some more, I noticed some logs like these:

cordova-android version check failed ("/app/platforms/android/cordova/version"), continuing anyways.

There were a couple of those, like 3 or 4, but the build did not stop when that happened.

I then ran the build of an older commit again, and it worked fine, probably because some layers were cached. But if I changed only a single package (I updated prettier to try it out), it caused most of the layers to be rebuilt and the build crashed with the above error.

It seems that somehow some dependencies deeper down got updated, which are causing the issue.

Thanks for your help.

like image 375
Andreas Gassmann Avatar asked Mar 22 '19 16:03

Andreas Gassmann


3 Answers

I have returned to the previous version: 8.1.2.

npm install -g [email protected]

Now, it's working again.

If you want to stay on the latest version of cordova, go to the following instructions:
https://stackoverflow.com/a/58956882/9536897

like image 181
Or Choban Avatar answered Nov 12 '22 06:11

Or Choban


Simple:

Replace the requireCordovaModule to require :

requireCordovaModule("q") to require("q")

like image 15
Khurshid Ansari Avatar answered Nov 12 '22 07:11

Khurshid Ansari


i can solve this issue by downgrading cordova to 8.1.1.

npm remove cordova -g && npm install -g [email protected]
like image 13
Alongkorn Avatar answered Nov 12 '22 06:11

Alongkorn