m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

Unable to find cordova binary, make sure it's installed. #103

Closed bernhardh closed 4 years ago

bernhardh commented 4 years ago

I have installed cordova globally:

$ npm install -g cordova
/home/bernhard/.npm-global/bin/cordova -> /home/bernhard/.npm-global/lib/node_modules/cordova/bin/cordova
+ cordova@9.0.0
updated 1 package in 7.299s

Then I created a new project and tried to add cordova:

vue create vuetest
cd vuetest
vue add cordova

And got the following result:

Installing vue-cli-plugin-cordova...

yarn add v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.11: The platform "linux" is incompatible with this module.
info "fsevents@1.2.11" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.2: The platform "linux" is incompatible with this module.
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ vue-cli-plugin-cordova@2.4.0
info All dependencies
└─ vue-cli-plugin-cordova@2.4.0
Done in 1.90s.
✔  Successfully installed plugin: vue-cli-plugin-cordova

🚀  Invoking generator for vue-cli-plugin-cordova...
✔  Successfully invoked generator for plugin: vue-cli-plugin-cordova
   The following files have been updated / added:

     src/assets/logo.svg
     src/plugins/vuetify.js
     vue.config.js
     package.json
     public/index.html
     src/App.vue
     src/components/HelloWorld.vue
     src/main.js
     yarn.lock

   You should review these changes with git diff and commit them.

 ERROR  cordova  Unable to find cordova binary, make sure it's installed.

I checked, if cordova is installed:

$ npm list -g --depth 0 | grep cordova
├── cordova@9.0.0
m0dch3n commented 4 years ago

is the cordova command working in your shell?

bernhardh commented 4 years ago
$ cordova -v
9.0.0 (cordova-lib@9.0.1)

yes

bernhardh commented 4 years ago

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).

bernhardh commented 4 years ago

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?

bernhardh commented 4 years ago

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?

m0dch3n commented 4 years ago

https://github.com/m0dch3n/vue-cli-plugin-cordova/blob/05506031fdf89bcfb8f95e1deaca5fa465bd7d64/package.json#L31

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

m0dch3n commented 4 years ago

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/

bernhardh commented 4 years ago

The long story short:

I removed node, reinstalled it with NVM and now everythings is working.

Thanks for your time!