简体   繁体   中英

Cordova is not recognized… immediately after installation

I'm stuck with this very frustrating problem while trying to install Apache Cordova. I issue npm install -g cordova in my cmd (Windows 8.1, 64 bits), and everything seems to be fine. But even after the installation when trying to type cordova it is not recognized as a command by the cmd . This is my first question on StackOverflow, so I may have missed something crucial or made a noob mistake. I hope someone out there can help me! :)

Cheers,

cmd session:

C:\Users\James>npm install -g cordova
npm http GET https://registry.npmjs.org/cordova

... bunch of text here ...

C:\Users\James\AppData\Roaming\npm\cordova -> C:\Users\James\AppData\Roaming\npm
\node_modules\cordova\bin\cordova
cordova@3.3.1-0.1.2 C:\Users\James\AppData\Roaming\npm\node_modules\cordova
├── ncallbacks@1.0.0
├── open@0.0.3
├── semver@1.1.0
├── colors@0.6.2
├── mime@1.2.11
├── q@0.9.7
├── follow-redirects@0.0.3 (underscore@1.5.2)
├── optimist@0.6.0 (wordwrap@0.0.2, minimist@0.0.5)
├── shelljs@0.1.2
├── glob@3.2.7 (inherits@2.0.1, minimatch@0.2.14)
├── lodash@2.4.1
├── elementtree@0.1.5 (sax@0.3.5)
├── tar@0.1.19 (inherits@2.0.1, block-stream@0.0.7, fstream@0.1.25)
├── xcode@0.6.2 (node-uuid@1.3.3, pegjs@0.6.2)
├── prompt@0.2.7 (revalidator@0.1.6, pkginfo@0.3.0, read@1.0.5, utile@0.1.7, win
ston@0.6.2)
├── request@2.22.0 (json-stringify-safe@4.0.0, aws-sign@0.3.0, forever-agent@0.5
.0, qs@0.6.6, tunnel-agent@0.3.0, oauth-sign@0.3.0, cookie-jar@0.3.0, node-uuid@
1.4.1, http-signature@0.10.0, hawk@0.13.1, form-data@0.0.8)
├── express@3.0.0 (methods@0.0.1, fresh@0.1.0, range-parser@0.0.4, debug@0.7.4,
cookie@0.0.4, crc@0.2.0, commander@0.6.1, mkdirp@0.3.3, send@0.1.0, connect@2.6.
0)
├── plist@0.4.3 (xmlbuilder@0.4.3, xmldom@0.1.17)
├── ripple-emulator@0.9.18 (connect-xcors@0.5.2, colors@0.6.0-1, accounting@0.3.
2, request@2.12.0, moment@1.7.2, express@3.1.0)
├── npm@1.3.22
├── plugman@0.17.0 (ncallbacks@1.1.0, osenv@0.0.3, bplist-parser@0.0.4, undersco
re@1.4.4, semver@2.0.11, nopt@1.0.10, dep-graph@1.1.0, rc@0.3.0, tar.gz@0.1.1, x
code@0.6.3, npm@1.3.4)
└── jshint@1.1.0 (peakle@0.0.1, cli@0.4.5, underscore@1.4.4, esprima@1.1.0-dev,
minimatch@0.2.14)

C:\Users\James>cordova
'cordova' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\James>cordova
'cordova' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\James>

It's likely that C:\\Users\\James\\AppData\\Roaming\\npm\\ isn't in your path so even though cordova is installed globally (as npm defines it) it isn't working as expected.

Use the SET command to check the value for your NODE_PATH or PATH . If the npm directory tree isn't listed...that's a problem, but easily fixed.

If you don't want npm to save to this directory, check the npm configuration options and the npm folders docs to see what you can change in this regard...

I just had this issue after a "successful" install, and found the cordova files under a folder called node modules in my users folder. I added c:\\users\\dewd\\node_modules\\cordova\\bin to my path, restarted a cmd prompt and then cordova ran ok.

They don't like to make it easy do they!!

Add this to your PATH

C:\Users\<USERNAME>\AppData\Roaming\npm\node_modules\cordova\bin

By default the folder

C:\Users\<USERNAME>\AppData 

is not visible. configure your explorer to see it or navigate through the CLI

if there still is not working check the PATH.

make sure the order is node; npm; cordova

example of the PATH

%JAVA_HOME%\bin;
%ANT_HOME%\bin;
%NODEJS%;
%NPM%;
C:\Program Files (x86)\WinAnt\bin;
C:\Program Files (x86)\Git\bin;
C:\Program Files (x86)\Git\cmd;
%CORDOVA%

To be very clean, create a new system variables NODEJS NPM CORDOVA

NODEJS="C:\\Program Files\\Nodejs"

NPM'="%appdata%\\npm\\;%USERPROFILE%\\AppData\\Roaming\\npm;"

CORDOVA="%USERPROFILE%\\AppData\\Roaming\\npm\\node_modules\\cordova\\bin"

Then edit the PATH in system variables and add %NODEJS% in front of anything that uses nodejs after add %NPM% and %CORDOVA% at the end.

this has been answered several times here...I will post my answer nonetheless.

In your prompt/terminal type this: npm config set prefix . Hope it helps ☺☺☺

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM