【Cordova Ionic】 Using “requireCordovaModule” to load non-cordova module “q” is not supported.【エラー解消】

ionic

こんにちは。たなかです。

IonicFrameworkでモバイルアプリ開発しています。

作業中に

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.

という内容のエラーでハマってしまったので、エラー内容と解決方法についてシェアしておきます。

同じ症状の方の助力に少しでもなれば幸いです。

エラー内容

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.

platform作成時に以下のエラーに遭遇しました。

> cordova platform add ios --verbose --save

You have been opted out of telemetry. To change this, run: cordova telemetry on.
Executing script found in plugin cordova-plugin-googlemaps for hook "before_platform_add": plugins/cordova-plugin-googlemaps/src/ios/check_sdk_version.js
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.
CordovaError: 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.
    at Context.requireCordovaModule (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/Context.js:57:15)
    at module.exports (/Users/tanakay/git/property/property-app-ionic/plugins/cordova-plugin-googlemaps/src/ios/check_sdk_version.js:5:15)
    at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:181:32)
    at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:157:16)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:125:20
    at process._tickCallback (internal/process/next_tick.js:68:7)
[ERROR] An error occurred while running subprocess cordova.

        cordova platform add ios --verbose --save exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.
  ionic:utils-process onBeforeExit handler: process.exit received +0ms
  ionic:utils-process onBeforeExit handler: running 1 functions +0ms
  ionic:utils-process onBeforeExit handler: exiting (exit code 1) +62ms
 
Ionic Cordovaプラグインの依存関係が原因かなーという第一印象でした。

指摘されているのはcordova-plugin-googlemapsみたいなので、切り分けのため、一旦こいつを消してみようかと考えました。

$ ionic cordova plugin remove cordova-plugin-googlemaps --verbose

ターミナルから上記のコマンドを実行。

第二のエラー

ところがその先でも以下のエラーに遭遇。内容は以下の通りです。

Executing script found in plugin cordova-plugin-googlemaps for hook "before_plugin_rm": plugins/cordova-plugin-googlemaps/src/before_plugin_rm.js
Using "requireCordovaModule" to load non-cordova module "fs" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
CordovaError: Using "requireCordovaModule" to load non-cordova module "fs" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
    at Context.requireCordovaModule (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/Context.js:57:15)
    at module.exports (/Users/tanakay/git/property/property-app-ionic/plugins/cordova-plugin-googlemaps/src/before_plugin_rm.js:3:16)
    at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:181:32)
    at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:157:16)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:125:20
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
[ERROR] An error occurred while running subprocess cordova.

        cordova plugin remove cordova-plugin-googlemaps --verbose --save exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.
  ionic:utils-process onBeforeExit handler: process.exit received +0ms
  ionic:utils-process onBeforeExit handler: running 1 functions +0ms
  ionic:utils-process onBeforeExit handler: exiting (exit code 1) +45ms

 

なんだか似たような怒られ方してますね。

plugin lsで確認しても、cordova-plugin-googlemapsは消えていません。

消すことも許されない。ワシぁどうしたらええんじゃ!!?!

解決方法

解消法を発見

 エラー内容で調査を進めると、以下のような内容の記事を発見。

英語の質問フォーラムなので、めちゃめちゃ意訳すると以下のような感じ。

キミは多分、Cordova v9を使ってるんじゃないか?

もしそうだとしたなら、それがキミの問題の根本原因だ。
v9で導入された変更が、プラグインと互換性がないんだよ。

残念だけど、互換性の問題が解決されるまでは、
一時的にCordovaをv8.1.2にダウングレードしてビルドするんだな。

 

なるほど。cordovaのバージョンが悪さしてるパターンかもしれません。

さっそくcordovaのバージョンを確認すると、案の定v9でした。

cordovaのバージョン変更

以下コマンドでバージョンを差し替えできます。

$ sudo npm uninstall -g cordova
$ sudo npm install -g cordova@8.1.2

 

とりあえずフォーラムでおすすめされてたv8.1.2にダウングレードします。

$ cordova -v
8.1.2 (cordova-lib@8.1.1)

 

バージョンが下がったことを確認できました。

再びplatformをaddしてみると、コマンドが成功しました! やったぜ!

【Cordova Ionic】 Using “requireCordovaModule” to load non-cordova module “q” is not supported. まとめ

ionic

Ionicでの開発はプラグインとの兼ね合いやバージョンによる齟齬でのエラーにやられることが結構あります。

エラー内容が親切に解消法を教えてくれる時もあれば、そうじゃない複雑な原因だったりもするので、後者だった時のハマり時間がエグいことになったりします。精進せねば。

 

今回はここまで。

参考サイト

https://forum.ionicframework.com/t/using-requirecordovamodule-to-load-non-cordova-module-glob-is-not-supported/161541

1 COMMENT

コメントを残す

メールアドレスが公開されることはありません。