0

I followed https://cordova.apache.org/docs/en/latest/guide/cli/ and https://www.youtube.com/watch?v=Vngqn6pS74A to install cordova. I have node 4.4.5 version.

When I gave the command C:>npm install -g cordova below are created in C drive seperately (not inside a one folder)

C:\

  • node_modules (folder)
  • cordova (win command script)
  • cordova (file)

I also get bellow errors,

npm WARN engine xmlbuilder@2.2.1: wanted: {"node":"0.8.x || 0.10.x"}       
 (current: {"node":"4.4.5","npm":"2.15.5"})
 npm WARN deprecated lodash-node@2.4.1: This package has been discontinued 
 in favor of lodash@^4.0.0.

when I type C:>cordova, it respnds the command. cordova version installed is 6.2.0

But if I call cordova in other directory eg: C:\CordovaProjects>cordova

then cordova command "is not recognized as an internal or external command"

What I am I doing wrong?

Thanks Mathee

p.s

C:\Users\MatheeshaF>npm config list
; cli configs
user-agent = "npm/2.15.5 node/v4.4.5 win32 x64"

; userconfig C:\Users\MatheeshaF\.npmrc
prefix = "C:\\"

; builtin config undefined

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\MatheeshaF
; HOME = C:\Users\MatheeshaF
; 'npm config ls -l' to show all defaults.

with help of comments I managed to create a project. still cannot add platform. Get below errors,

 C:\CordovaProjects\TestApp>cordova platform add android
    Error: Failed to fetch platform android
    Probably this is either a connection problem, or platform spec is incorrect.
    Check your connection and platform name/version/URL.
    Error: connect EACCES 103.245.222.162:443
Mathee
  • 691
  • 7
  • 16
  • 1
    is npm in your path? execute this command `npm config get prefix` and make sure that the resulting output is in your path – dariru Jun 10 '16 at 06:27
  • Dar Thanks for the cooment. I get errors when run your command. C:\>npm config prefix npm ERR! Usage: npm ERR! npm config set npm ERR! npm config get [] npm ERR! npm config delete npm ERR! npm config list npm ERR! npm config edit npm ERR! npm set npm ERR! npm get [] – Mathee Jun 10 '16 at 06:45
  • 1
    I think you forgot to add `get` before `prefix` – dariru Jun 10 '16 at 06:50
  • ohhh yes! I get below now C:\Users\MatheeshaF>npm config get prefix C:\ – Mathee Jun 10 '16 at 06:52
  • now what is the issue. why can;t I use cordova command inside sub directories as in https://www.youtube.com/watch?v=Vngqn6pS74A – Mathee Jun 10 '16 at 06:55
  • I am wondering why your npm is set to that folder, haha but anyway. Is the output of `npm bin -g` the same as that? and also do `npm list -g` and show us the first output line only – dariru Jun 10 '16 at 07:03
  • please see the end of my question – Mathee Jun 10 '16 at 07:05

3 Answers3

2

Your npm prefix is not set properly.

  1. Run npm bin -g and npm config get prefix
  2. If there is a result other than C:\\, add this to your path

It should look similar to this

%USERPROFILE%\AppData\Roaming\npm

You can refer here how to do it in windows 10 https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10

For Windows 10,

Settings > System > About > System Info > Environmental Variables 

Edit path and append %USERPROFILE%\AppData\Roaming\npm at the end

  1. set your npm prefix by npm config set prefix %USERPROFILE%\AppData\Roaming\npm
Community
  • 1
  • 1
dariru
  • 501
  • 6
  • 16
  • I get below instead C:\>npm bin -g C:\(not in PATH env variable) – Mathee Jun 10 '16 at 07:16
  • I see then that is the problem. Go refer to the link I put on how to set up your path variable. – dariru Jun 10 '16 at 07:18
  • I went to %USERPROFILE%\AppData\Roaming\npm and it only has a empty folder named etc – Mathee Jun 10 '16 at 07:18
  • 1
    set your prefix to that folder and add it to the path – dariru Jun 10 '16 at 07:27
  • and where should I run the install -g cordova command, C:\ or C:\Users\your-user-name> – Mathee Jun 10 '16 at 07:46
  • 1
    if `npm` is already in your path (meaning, the folder mentioned above is already in your environment variable `path`), then running `npm install -g cordova` anywhere is fine in cmd. After doing so, you can follow the instructions in the get started cordova website on how to create the app. – dariru Jun 10 '16 at 07:56
  • almost all went ok I guess. I created a project. but issue occurred when adding android platform. Please check end of my question. It would be great if you can help me out. – Mathee Jun 10 '16 at 08:19
  • @Mathee hello, glad it worked but as much as I would like to help you from here, I think a new question should be asked. For starters, here's a possible same question http://stackoverflow.com/questions/35451207/cordova-error-failed-to-fetch-platform-android – dariru Jun 10 '16 at 08:29
1

You need to run this command at

C:\Users\your-user-name>npm install -g cordova

rahlrokks
  • 451
  • 1
  • 4
  • 12
  • this didn't work for me. I can still run command C:>cordova. But gives errors on C:\CordovaProjects>cordova – Mathee Jun 10 '16 at 06:48
  • Is npm accessible under C:\CordovaProjects? – rahlrokks Jun 10 '16 at 06:50
  • Yes! C:\CordovaProjects>npm gives npm descriptions – Mathee Jun 10 '16 at 06:57
  • It seems some issue with your computer try restarting it. And just to start work you can install cordova locally into this folder. C:\CordovaProjects>npm install cordova – rahlrokks Jun 10 '16 at 07:00
  • is it normal to have above mentioned cordova files and folders created just on C: – Mathee Jun 10 '16 at 07:04
  • @Mathee no it is not normal, unless it was reconfigured before – dariru Jun 10 '16 at 07:05
  • I am usng windows 10 and this is the first time I am trying on cordova. I even installed java new version, android studio before this – Mathee Jun 10 '16 at 07:08
  • I have used cordova on windows 10 and it works fine. So it is not a issue of windows 10. – rahlrokks Jun 10 '16 at 07:12
  • 1
    add this path to "C:\Users\user-name\AppData\Roaming\npm;" to path in system variables and after adding it, open a fresh command window and run npm install -g cordova – rahlrokks Jun 10 '16 at 07:22
  • I get C:\WINDOWS\system32> as fresh command prompt. where should i direct – Mathee Jun 10 '16 at 07:49
  • Thanks for the help. I also had to set npm config set prefix %USERPROFILE%\AppData\Roaming\npm to make it work – Mathee Jun 10 '16 at 09:36
1

First thing is to ensure that you install cordova globally using the -g option as follows:

npm install -g cordova

Also ensure that nodejs installtion path is set in system environment's Path variable.

Infact if you follow the Official Cordova CLI guide properly, you wont face such issues as even the nodejs path setting will also happen automatically.

Your platform add android command is failing due to connection issue. Ensure that your firewall network or anti virus is not blocking the dependency downloads while adding android platform.

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • as you can see in my question I had already done what you mentioned. Thanks for helping hand. – Mathee Jun 10 '16 at 09:38
  • Yes, the answer I marked solved it to the the point I initially asked for. But still I cannot add android platform. See the end of my question. Please help if can – Mathee Jun 10 '16 at 10:06
  • 1
    @Mathee Are you using proxy connection or behind wirefall network. It looks like a connection issue – Gandhi Jun 10 '16 at 10:10