cordova-cli
cordova-cli copied to clipboard
Missing git leads to not obvious error message on `platform add`
Bug Report
Problem
For complicated reasons [1] I am trying to run cordova platform add https://github.com/apache/cordova-windows
in a temporarily elevated prompt. The way my system is set up, git
is only installed on my user account, but not for Admin.
This caused this non obvious (to me) error message:
PS E:\Projects\throwaway\cordovaAdminWindowsNpmFail> cordova platform add https://github.com/apache/cordova-windows
Using cordova-fetch for https://github.com/apache/cordova-windows
Failed to fetch platform https://github.com/apache/cordova-windows
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR! path git
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn git
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t https://github.com/apache/cordova-windows.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2019-07-03T11_36_43_837Z-debug.log
After installing git
for the Admin user, this problem is gone.
Maybe we can give better error messages here?
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
[1] I am trying to get Paramedic CI to work for cordova-windows. As AppVeyor, the CI we use runs in admin mode, I have to remove an exception from cordova-windows that is thrown if run in an admin prompt. To test this, I am trying to run paramedic's Windows tests locally, which works for non-admin prompts, but not admin ones. To understand I am trying to run the commands manually, but encountered this problem.
We've had this as an issue before. I believe I closed it as wontfix. Problem is that we never even call git ourselves. We just transparently pass any spec through to npm
. So actually it is npm that should provide a better error message IMHO
Yeah, I had something like that in the back of my mind - as it cost me a good 15 minutes I thought this maybe might be different a different case and worth trying 🤷♀
Bad npm 🐕
Bad npm 🐕
😂
I mean I totally agree that it would be nice to have a better error message in this case.
Here is the issue on npm.community: https://npm.community/t/error-git-not-found/154
I think npm
should be modified to check that git
is installed, using which
for example, before attempting to spawn git
. From a quick look through the npm code, it does not look like a super-trivial fix : which
seems to return a standard Promise while spawn seems to use a Node.js EventEmitter.
Handling the error with a more explicit error message after it failed would actually be enough.