Ionic serve does not work but "npm run ionic:serve" works

All of the sudden ionic serve has stopped working and only produces the following lines and then nothing happens:

[INFO] Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 - Ctrl+C to cancel
[23:18:43] watch started …
[23:18:43] build dev started …

The following command works as expected though:

npm run ionic:serve

Even the ionic info command does not work and only produces this:

| Gathering environment info

I don’t know what I’ve done that ionic serve is not working. The only thing that might have led to this is running npm cache clean --force.

How can I get this fixed?

Run the commands with --verbose. Anything interesting?

@Sujan12 The output of ionic serve --verbose:

[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: ‘e:\projects\my-app’, local: false, binPath: ‘C:\Users\username\AppData\Roaming\npm\node_modules\ionic\bin\ionic’, libPath: ‘C:\Users\username\AppData\Roaming\npm\node_modules\ionic\dist\index.js’ }
[DEBUG] New daemon pid: 7480
[INFO] Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 - Ctrl+C to cancel
[01:01:17] watch started …
[01:01:17] build dev started …

Another time I ran the command it produced the following and stopped:

[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: ‘e:\projects\my-app’, local: false, binPath: ‘C:\Users\username\AppData\Roaming\npm\node_modules\ionic\bin\ionic’, libPath\node_modules\ionic\dist\index.js’ }
[DEBUG] New daemon pid: 10620
[INFO] Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 - Ctrl+C to cancel
[01:16:13] watch started …
[01:16:13] build dev started …
[01:16:13] clean started …
[01:16:13] clean finished in 5 ms
[01:16:13] copy started …
[01:16:13] transpile started …
[01:16:32] transpile finished in 18.97 s
[01:16:32] preprocess started …
[01:16:32] deeplinks started …
[01:16:33] deeplinks finished in 450 ms
[01:16:33] preprocess finished in 452 ms
[01:16:33] webpack started …

But that was only one time. Running ionic serve --verbose again gives this:

[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: ‘e:\projects\my-app’, local: false, binPath: ‘C:\Users\username\AppData\Roaming\npm\node_modules\ionic\bin\ionic’, libPath: ‘C:\Users\username\AppData\Roaming\npm\node_modules\ionic\dist\index.js’ }
[DEBUG] New daemon pid: 10980
[INFO] Starting app-scripts server: --address 0.0.0.0 --port 8100 --livereload-port 35729 - Ctrl+C to cancel
[01:17:44] watch started …
[01:17:45] build dev started …

I guess I need to reinstall ionic from scratch…

Try that.

I have seen similar problems a few times posted here in the past, but never a real reason or real way out of it.

I uninstalled cordova and ionic:

npm uninstall -g ionic cordova

And installed them again:

npm install -g cordova ionic

Unfortunately the problem persists. Any suggestion?

One solution: Uninstall your node, install nvm (or nvm-windows if you are on Windows), install a new node (which includes npm) with this, then install ionic and cordova again and try your command again. Very often this helps.

2 Likes

Yea the problem was fixed but I had to also delete all the old npm and nodejs directories in c:\program files\nodejs. Thanks for the help.

1 Like