Cordova-plugin-googlemaps: Error: Cannot find module 'C:\Users\user_name\cordovawork\app_name\node_modules\xml2js'

Created on 30 Mar 2018  Â·  22Comments  Â·  Source: mapsplugin/cordova-plugin-googlemaps

i tried to install according to quick install (https://github.com/mapsplugin/cordova-plugin-googlemaps) but got following error. i already spent 2 days. please help.

C:Users\user_name\cordovawork\app_name>cordova plugin add cordova-plugin-googlemaps --va
riable API_KEY_FOR_ANDROID="..." --variable API_KEY_FOR_IOS="..."
Fetching plugin "cordova-plugin-googlemaps" via npm
Installing "cordova-plugin-googlemaps" for android
Failed to install 'cordova-plugin-googlemaps':Error: Cannot find module 'C:User
s\user_name\cordovawork\app_name\node_modules\xml2js'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at module.exports (C:Users\user_name\cordovawork\app_name\plugins\cordova-plugin-goo
glemaps\src\before_plugin_install.js:17:16)
at runScriptViaModuleLoader (C:Users\user_name\AppData\Roaming\npm\node_modules\c
ordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:187:18)
at runScript (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_mod
ules\cordova-lib\src\hooks\HooksRunner.js:165:16)
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\cordov
a-lib\src\hooks\HooksRunner.js:133:20
at _fulfilled (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_mo
dules\q\q.js:787:54)
at self.promiseDispatch.done (C:Users\user_name\AppData\Roaming\npm\node_modules\
cordova\node_modules\q\q.js:816:30)
Error: Cannot find module 'C:Users\user_name\cordovawork\app_name\node_modules\xml2js'

C:Users\user_name\cordovawork\app_name>npm install xml2js
[email protected] node_modules\xml2js
├── [email protected]
└── [email protected]

C:Users\user_name\cordovawork\app_name>cordova plugin add cordova-plugin-googlemaps --va
riable API_KEY_FOR_ANDROID="..." --variable
API_KEY_FOR_IOS="..."
Installing "cordova-plugin-googlemaps" for android
Failed to install 'cordova-plugin-googlemaps':Error: Cannot find module 'C:User
s\user_name\cordovawork\app_name\node_modules\minimist'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at C:Users\user_name\cordovawork\app_name\plugins\cordova-plugin-googlemaps\src\befo
re_plugin_install.js:211:22
at Function.promise (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\n
ode_modules\q\q.js:635:9)
at C:Users\user_name\cordovawork\app_name\plugins\cordova-plugin-googlemaps\src\befo
re_plugin_install.js:151:14
at _fulfilled (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_mo
dules\q\q.js:787:54)
at self.promiseDispatch.done (C:Users\user_name\AppData\Roaming\npm\node_modules\
cordova\node_modules\q\q.js:816:30)
at Promise.promise.promiseDispatch (C:Users\user_name\AppData\Roaming\npm\node_mo
dules\cordova\node_modules\q\q.js:749:13)
Error: Cannot find module 'C:Users\user_name\cordovawork\app_name\node_modules\minimist'

C:Users\user_name\cordovawork\app_name>npm install minimist
[email protected] node_modules\minimist

C:Users\user_name\cordovawork\app_name>cordova plugin add cordova-plugin-googlemaps --va
riable API_KEY_FOR_ANDROID="AIzaSyCmgNkbGBQCTNd6dk0q9xEjqnFzEMNey9o" --variable
API_KEY_FOR_IOS="AIzaSyCBAEfX8eeRWcG7_dTaTYWrH3SEG-k7M68"
Installing "cordova-plugin-googlemaps" for android
ANDROID_HOME=C:Users\user_name\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111
Subproject Path: CordovaLib
Incremental java compilation is an incubating feature.
:clean
:CordovaLib:clean

BUILD SUCCESSFUL

Total time: 1 mins 17.789 secs
Subproject Path: CordovaLib

        Official document
        https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/mas

ter/v2.0.0/README.md

Installing "cordova-plugin-googlemaps" for browser
Error loading cordova-browser
Installing "cordova-plugin-googlemaps" for ios
apple-xcode version check failed ("C:Users\user_name\cordovawork\app_name\platforms\ios\
cordova\apple_xcode_version"), continuing anyways.
apple-ios version check failed ("C:Users\user_name\cordovawork\app_name\platforms\ios\co
rdova\apple_ios_version"), continuing anyways.
support for subdirectories is deprecated and will be removed in Cordova@7
Fetching plugin "https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git
" via git clone
Failed to install 'cordova-plugin-googlemaps':CordovaError: Failed to fetch plug
in https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git via git.
Either there is a connection problems, or plugin spec is incorrect:
Error: "git" command line tool is not installed: make sure it is accessi
ble on your PATH.
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\cordov
a-lib\src\plugman\fetch.js:103:33
at _rejected (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_mod
ules\q\q.js:797:24)
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js
:823:30
at Promise.when (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_
modules\q\q.js:1035:31)
at Promise.promise.promiseDispatch (C:Users\user_name\AppData\Roaming\npm\node_mo
dules\cordova\node_modules\q\q.js:741:41)
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js
:557:44
at flush (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules
\q\q.js:108:17)
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
Error: Failed to fetch plugin https://github.com/mapsplugin/cordova-plugin-googl
emaps-sdk.git via git.
Either there is a connection problems, or plugin spec is incorrect:
Error: "git" command line tool is not installed: make sure it is accessi
ble on your PATH.

C:Users\user_name\cordovawork\app_name>cordova plugin add cordova-plugin-googlemaps --va
riable API_KEY_FOR_ANDROID="..." --variable
API_KEY_FOR_IOS="..."
Plugin "cordova-plugin-googlemaps" already installed on android.
Plugin "cordova-plugin-googlemaps" already installed on browser.
Installing "cordova-plugin-googlemaps" for ios
apple-xcode version check failed ("C:Users\user_name\cordovawork\app_name\platforms\ios\
cordova\apple_xcode_version"), continuing anyways.
apple-ios version check failed ("C:Users\user_name\cordovawork\app_name\platforms\ios\co
rdova\apple_ios_version"), continuing anyways.
support for subdirectories is deprecated and will be removed in Cordova@7
Fetching plugin "https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git
" via git clone
Failed to install 'cordova-plugin-googlemaps':CordovaError: Failed to fetch plug
in https://github.com/mapsplugin/cordova-plugin-googlemaps-sdk.git via git.
Either there is a connection problems, or plugin spec is incorrect:
Error: "git" command line tool is not installed: make sure it is accessi
ble on your PATH.
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\cordov
a-lib\src\plugman\fetch.js:103:33
at _rejected (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_mod
ules\q\q.js:797:24)
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js
:823:30
at Promise.when (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_
modules\q\q.js:1035:31)
at Promise.promise.promiseDispatch (C:Users\user_name\AppData\Roaming\npm\node_mo
dules\cordova\node_modules\q\q.js:741:41)
at C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js
:557:44
at flush (C:Users\user_name\AppData\Roaming\npm\node_modules\cordova\node_modules
\q\q.js:108:17)
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
Error: Failed to fetch plugin https://github.com/mapsplugin/cordova-plugin-googl
emaps-sdk.git via git.
Either there is a connection problems, or plugin spec is incorrect:
Error: "git" command line tool is not installed: make sure it is accessi
ble on your PATH.

Most helpful comment

I took a look at \plugins\cordova-plugin-googlemaps\src\before_plugin_install.js and figured I probably needed some of what was in it. So instead of deleting it, I changed this line:

exec('npm install xml2js minimist --save 2>&1', function(err, stdout) {

to this:

exec('cd '+__dirname+'; npm install xml2js minimist --save 2>&1', function(err, stdout) {

and then the installation appeared to work correctly.

All 22 comments

Getting a similar error except it says:

Cannot find module '...plugins\cordova-plugin-googlemaps\node_modules\minimist'

Edit: I noticed that minimist folder was indeed missing from plugins\cordova-plugin-googlemaps\node_modules\minimist. I manually installed minimist through NPM and manually copied the folder over to the expected location. It seemed to install successfully this time, but not sure if something else is missing or needed....

Remove the app_name\plugins\cordova-plugin-goo glemaps\src\before_plugin_install.js. That is the easiest solution.

@wf9a5m75 Thank you for the help! That file is it not needed at all?

Read the code. If you feel you don't need it, remove it.

@wf9a5m75 Usually installing a library should not require reading the libraries internal code to fix bugs...

The word Usually is not equal with must.
And this bug is already fixed in the multiple_maps branch.

@wf9a5m75 So not only do we need to know about your libraries internal code but also some random branches in the repo... Your not making you case any better.

Because of historical reason, this plugin uses only two branches:

  • master branch is for the same as npm
  • multiple_maps branch is for the next development version.

Anyway, I didn't ask you to use this plugin mandatory. If you don't like this plugin, you just use another plugin.

Thanks for comments. As hvaughan3 commented, I installed "xml2js" and "minimist" in "plugins\cordova-plugin-googlemaps\node_modules" directory but still get same error ↓

Error: Failed to fetch plugin https://github.com/mapsplugin/cordova-plugin-googl
emaps-sdk.git via git.
Either there is a connection problems, or plugin spec is incorrect:
Error: "git" command line tool is not installed: make sure it is accessi

ble on your PATH.

No solution?

@nagaiku What happens when you type in the command shell (in any directory):
git --version

Oh, thanks for reply, makers-mark. I simply installed "git for windows", I installed the plugin at last. But my sample code doesn't work. I coded like this.↓

var map;
document.addEventListener("deviceready", function() {
var div = document.getElementById("map_canvas");
map = plugin.google.maps.Map.getMap(div);

}, false);

Try to execute by command "cordova serve android", the message "Uncaught ReferenceError: plugin is not defined" is appeared on console.

Or try to execute by command " cordova run android -device -d" on my device, following error is appeared.

Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Build file 'C:Users\user_name\cordovawork\app_name\platforms\android\build.gradle' line:
    253

  • What went wrong:
    A problem occurred evaluating root project 'android'.

    Could not get unknown property 'PLAY_SERVICES_VERSION' for object of type org.
    gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 11.357 secs
Command finished with error code 1: cmd /s /c "C:Users\user_name\cordovawork\app_name\pl
atforms\android\gradlew.bat cdvBuildDebug -b C:Users\user_name\cordovawork\app_name\plat
forms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx204
8m -Pandroid.useDeprecatedNdk=true"
Error: cmd: Command failed with exit code 1 Error output:

FAILURE: Build failed with an exception.

  • Where:
    Build file 'C:Users\user_name\cordovawork\app_name\platforms\android\build.gradle' line:
    253

  • What went wrong:
    A problem occurred evaluating root project 'android'.

    Could not get unknown property 'PLAY_SERVICES_VERSION' for object of type org.
    gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.
    at ChildProcess.whenDone (C:Users\user_name\cordovawork\app_name\platforms\android\c
    ordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:818:16)
    at Socket. (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)

    at Pipe._onclose (net.js:469:12)

Please any help.

cordova serve is not supported.

Oh thanks. But tried to run on my device by command "cordova run android -device -d" on my real device, build failed like I wrote above. The error message is too difficult to solve for me. I think the point is "Could not get unknown property 'PLAY_SERVICES_VERSION' for object of type org.
gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.".

$> cordova plugin add cordova-plugin-googlemaps \
    --variable API_KEY_FOR_ANDROID="..." \
    --variable API_KEY_FOR_IOS="..." \
    --variable PLAY_SERVICES_VERSION="11.8.0" \
    --variable ANDROID_SUPPORT_V4_VERSION ="24.1.0"

Thanks a lot, Masashi Katsumata!! But I got "Error: invalid variable format: ANDROID_SUPPORT_V4_VERSION"

Oh sorry, I removed the space " " before "ANDROID_SUPPORT_V4_VERSION", the command is succeeded. But the following messages are appeared.
"
Plugin "cordova-plugin-googlemaps" already installed on android.
Plugin "cordova-plugin-googlemaps" already installed on browser.
Plugin "cordova-plugin-googlemaps" already installed on ios.
"
Plugin is alreday installed on each platform.

You need to remove the previous installed plugin before installing.

Thanks advice. I remove and re-installed plugin, still got error. So I changed the "\platforms\android\project.properties" as follows:

Project target.

target=android-24
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-googlemaps/bymap-tbxml-android.gradle
cordova.system.library.1=com.google.android.gms:play-services-maps:11.8.0

$PLAY_SERVICES_VERSION

cordova.system.library.2=com.google.android.gms:play-services-location:11.8.0

$PLAY_SERVICES_VERSION

cordova.system.library.3=com.android.support:support-core-utils:24.1.0

#$ANDROID_SUPPORT_V4_VERSION

Then build is successful. But the screen is white, cannot catch any error.

For the very first beginner, please create an empty project with this sample.
Please don't try with your project from the first.
https://github.com/mapsplugin/cordova-plugin-googlemaps#quick-demo

Many thanks. Finally, I could run the app. This app is very useful.

I took a look at \plugins\cordova-plugin-googlemaps\src\before_plugin_install.js and figured I probably needed some of what was in it. So instead of deleting it, I changed this line:

exec('npm install xml2js minimist --save 2>&1', function(err, stdout) {

to this:

exec('cd '+__dirname+'; npm install xml2js minimist --save 2>&1', function(err, stdout) {

and then the installation appeared to work correctly.

@AntoneRoundy You sir deserve a medal of honour.

Was this page helpful?
0 / 5 - 0 ratings