Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Ionic 2) An Error occurred trying to fall back to Cordova-lib execution: TypeError: Cannot read property 'then' of undefined

Edit: This is happening when working with ionic 2. I know it's not stable yet, but i assume that there may be some fix for this, since it seems like others don't get this problem. Edit end

For some reason i've suddenly started to get this error when trying to build my ionic app, using "ionic build android", and also "ionic build ios":

An Error occurred trying to fall back to Cordova-lib execution: TypeError: Cannot read property 'then' of undefined
at Object.IonicTask.runCordova (/usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:262:21)
at /usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:142:19
at _fulfilled (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/ionic/node_modules/q/q.js:557:44
at flush (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:108:17)
at doNTCallback0 (node.js:430:9)
at process._tickCallback (node.js:359:13)

Error happened [TypeError: Cannot read property 'then' of undefined]
    TypeError: Cannot read property 'then' of undefined
at Object.IonicTask.runCordova (/usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:262:21)
at /usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:142:19
at _fulfilled (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/ionic/node_modules/q/q.js:557:44
at flush (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:108:17)
at doNTCallback0 (node.js:430:9)
at process._tickCallback (node.js:359:13)

I'm lost here, and have no idea where to start looking.

Is there anyone who has seen this before, and can point me in the right direction?

like image 312
larschla Avatar asked Dec 03 '15 05:12

larschla


3 Answers

@mabs @mgcdanny

I am pretty certain I've figured out the root cause to the issue. I ran cordova -v and saw this output -

Ross-MBP:test rossmartin$ cordova -v
/usr/local/lib/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:53
                throw err;
                ^

Error: EACCES: permission denied, open '/Users/rossmartin/.config/configstore/update-notifier-cordova.json'
You don't have access to this file.

I then ran

Ross-MBP:test rossmartin$ sudo chown -R rossmartin ~/.config
Ross-MBP:test rossmartin$ cordova -v
6.0.0

Now I see cordova reporting it is at 6.0.0 and can do ionic build/prepare again.

I think what happened is that the Ionic CLI did not think that the cordova CLI was installed. Maybe it is possible that somewhere the Ionic CLI does a cordova -v and was getting hung up by the permission issue reading the ~/.config/configstore/update-notifier-cordova.json file.

like image 196
Ross Avatar answered Nov 14 '22 03:11

Ross


I had the same issue on Ubuntu.

I needed to install a few dependencies.

Firstly cordova, with:

npm install -g cordova

The Android SDK from http://developer.android.com/sdk/index.html

And a Java SDK.

like image 20
mabs Avatar answered Nov 14 '22 01:11

mabs


uninstall globally (use sudo if needed)

sudo npm uninstall -g ionic
sudo npm uninstall -g ionic@beta
sudo npm uninstall -g cordova

fix permissions like this: https://docs.npmjs.com/getting-started/fixing-npm-permissions

this worked for me:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

reinstall (without sudo)

npm install -g ionic
npm install -g ionic@beta
like image 3
mgcdanny Avatar answered Nov 14 '22 01:11

mgcdanny