Cannot read property 'serve:before' of undefined (CLI v2.2.3)

im trying to serve a Moodle mobile app, this is the repo:

this is the log when i try - ionic serve, after clone the project and do - npm run setup :


TypeError: Cannot read property 'serve:before' of undefined
    at Object.runWithGulp (/usr/local/lib/node_modules/ionic/lib/cli.js:237:17)
    at Object.runr (/usr/local/lib/node_modules/ionic/lib/cli.js:194:18)
    at /usr/local/lib/node_modules/ionic/lib/cli.js:54:9
    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 _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)


Cannot read property 'serve:before' of undefined (CLI v2.2.3)

Your system information:

Cordova CLI: 8.0.0 
Ionic Framework Version: 3.9.2
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 3.1.9
ios-deploy version: Not installed
ios-sim version: 6.1.2 
OS: macOS
Node Version: v6.0.0
Xcode version: Xcode 10.1 Build version 10B61


I had the same issue. Don’t know if it can help, though, try reinstalling everything because some versions of node and npm install deprecated versions of ionic, gulp and cordova. So getting a fresh install of every dependency can solve them problem. Y

ou should probably need to remove platforms, node_modules and plugins and run npm run setup again.

More:
My problem was deeper, because I had multiple node installations in my mac, including installations using homebrew and nvm. I uninstalled all of them including nvm itself, then I went in every dependency folder and deleted folders manually.

After that I downloaded the latest NodeJS LTS version (.pkg) from NodeJS website and installed it from the wizard. That restored node and npm, finally I resintalled all dependencies (cordova, ionic and gulp) using the latest npm, and it solved the problem.

Always install them using sudo for super user permissions and -g flag for global installation.

solution for this is simple just update your ionic CLI to the latest versions in order to do that jst follow the following commands

npm remove ionic --save -dev

npm i -g ionic@latest (installing globally)