问题
My question
I am learning to make a hybrid application with cordova apache (previously Phonegap?) I am following the steps they recommend our their website:
https://cordova.apache.org/docs/en/latest/guide/cli/index.html
I successfully installed nodeJS (if I do the command node --version, it will return its version)
But when I try to install cordova, everything seems working, but not the CLI.
So: I guess the CLI is configured incorrect, but I am not sure. Anyone can help me here?
Notes:
Command used to install cordova (globally):
npm install -g cordova
Command used to check if it was installed correctly and accessible from the command line (with given errors):
cordova --version module.js:340 throw err; ^ Error: Cannot find module 'c:\Program Files\nodejs\node_modules\cordova\bin\cordova' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:289:25) at Function.Module.runMain (module.js:457:10) at startup (node.js:138:18) at node.js:974:3
I found out the path in the error doesn't exist:
c:\Program Files\nodejs\node_modules\cordova\bin\cordova
The correct path have to be:
C:\Users\Username\AppData\Roaming\npm\node_modules\cordova\bin\cordova
I configured this path in my global system environments:
C:\Users\Username\AppData\Roaming\npm
I noticed this file (which needs to be called from CLI I guess)
#!/bin/sh basedir=`dirname "$0"` case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac if [ -x "$basedir/node" ]; then "$basedir/node" "$basedir/node_modules/cordova/bin/cordova" "$@" ret=$? else node "$basedir/node_modules/cordova/bin/cordova" "$@" ret=$? fi exit $ret
I am working on Windows 8
回答1:
I faced the same issue recently. Solved it by doing the following:
npm -g install npm
npm install -g cordova
The issue was that the version of npm that is bundled with the latest stable version of node does not support some packages.
回答2:
In windows inside the root folder of the project I found two files cordova.cmd an cordova. Delete those two files
来源:https://stackoverflow.com/questions/33926761/cordova-apache-wrong-module-path