Closed bernhardh closed 4 years ago
is the cordova command working in your shell?
$ cordova -v
9.0.0 (cordova-lib@9.0.1)
yes
And just to make it clear, I can run cordova in the shell without any problems:
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add android
cordova emulate android
And everythings works (I see the emulator and the cordova welcome page).
I think I tracked it down, maybe you have an idea.
I created a new script called test1.js
, which only calls cordova -v
:
const { spawn } = require( 'child_process' );
const ls = spawn( 'cordova', [ '-v' ] );
ls.stdout.on( 'data', data => {
console.log( `stdout: ${data}` );
} );
ls.stderr.on( 'data', data => {
console.log( `stderr: ${data}` );
} );
ls.on( 'close', code => {
console.log( `child process exited with code ${code}` );
} );
And when I run it, I get
events.js:298
throw er; // Unhandled 'error' event
^
Error: spawn cordova ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn cordova',
path: 'cordova',
spawnargs: [ '-v' ]
}
But when I change the path in line 2 to the absolute path:
const ls = spawn( /home/username/.npm-global/bin/'cordova', [ '-v' ] );
It works and I get
stdout: 9.0.0 (cordova-lib@9.0.1)
stdout:
child process exited with code 0
Any ideas?
New update, I have tracked it down a bit.
When using /bin/bash
as shell it works:
const cmd = spawn('cordova', ['-v'], {
shell: '/bin/bash'
});
Do you know, if I have to set this somewhere global? Or why its not working without?
I think it's related to this library, which got merged here https://github.com/m0dch3n/vue-cli-plugin-cordova/commit/223849473ca3e1e38b4ba70cc62412687a192f96
On my environment and most of the other users (over 1500 weekly downloads on npm) , this seems no not be an issue
So unfortunately, I don't have any idea, how to help you...
Maybe you find more infos in the issue tracker of hasbin
btw if its working in one shell, but not the other, and with an absolute path, maybe you can check your $PATH with echo $PATH
an see if it includes /home/username/.npm-global/bin/
The long story short:
I removed node, reinstalled it with NVM and now everythings is working.
Thanks for your time!
I have installed cordova globally:
Then I created a new project and tried to add cordova:
And got the following result:
I checked, if cordova is installed: