(Ionic 2) An Error occurred trying to fall back to

2019-06-17 10:46发布

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?

4条回答
甜甜的少女心
2楼-- · 2019-06-17 11:16

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-06-17 11:17

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
查看更多
4楼-- · 2019-06-17 11:21

The build process was looking for Cordova-lib and could not find it. This is usually caused if you have not installed Cordoval-CLI

To check if you have cordova-CLI installed, type $ ionic info Check the result. if you see Cordova CLI: Not installed run npm install -g cordova@4.2.0 $ ionic info > it should show Cordova CLI: 4.2.0

查看更多
做个烂人
5楼-- · 2019-06-17 11:27

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

查看更多
登录 后发表回答