Error occurred trying to fall back to Cordova-lib execution

Im getting error when want to build even on a blank starter template app
Please help

$ 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:419:9) at process._tickCallback (node.js:348: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:419:9) at process._tickCallback (node.js:348:13)

I get the same here.

It works if i put sudo in front of ā€œionic build iosā€, but then all the files generated is owned by root user, and not by my user.

So why does it work with sudo, and not without?

1 Like

Its because of CHOWN\CHMOD permissions of folderā€¦
Best solution is uninstall cordova\ionic and reinstall it,if this needed chown -R username /cordovapath/

I did reinstall ionic and cordova, multiple times, and ran CHOWN and CHMOD on the folders. No luck. Still the same error.

Not sure if i am running CHOWN and CHMOD on the right folders. Iā€™ve ran it on more or less everything i can find that has to do with ionic/cordova.

I am facing same issue now. Have you found any workaround?

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

I also installed the Android SDK

Just did these steps, but unfortunately, still same error.

Thanks anyway :slight_smile:

Same hereā€¦ didnā€™t work for me either :(. But thanks anyway

I found a fix. Iā€™m on mac. so sudo is a must to install npm -g packages unless you do this: http://www.johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/. The issue doesnā€™t seem to be with sudo though.

Looking into /usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:296 code made me realize that ionic throws this error when it canā€™t find cordova-cli. Then, running ionic info showed Cordova CLI: Not installed. Although I installed cordova and its in standard npm path, ionic didnā€™t pick it up. Looking around showed that ionic works well with cordova@4.2.0.

sudo npm install -g cordova@4.2.0
ionic info > it should show Cordova CLI: 4.2.0
ionic build android

This time it worked!

3 Likes

Yep, that did the trick! Works fine now.

Thanks for sharing.

I have the same problem. Unfortunately the proposed solution did not work for me. After I installed cordova 4.2 I still get 6.0 when I type in ā€˜sudo version -vā€™.

@cybernatic @a4anishm @syedtariq @larschla

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 as @a4anishm pointed out. 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.

1 Like

Great stuff Ross! This worked for me, thanks!

Great, Thanks a lot!