David Rocha
David Rocha

Reputation: 549

Ionic 4 - Getting [ERROR] ng has unexpectedly closed (exit code 1) when I run "ionic server"

I am struggling in this error when I try the first run on an Ionic4 project.

ng run app:serve --host=0.0.0.0 --port=8100

[ERROR] ng has unexpectedly closed (exit code 1).

  The Ionic CLI will exit. Please check any output above for error details.

I'm using Linux Elementary OS (a nice distro that came from Ubuntu).

I tried to run a ionic3 project and it ran successfully.

When I run ionic serve --verbose I get this message

enter image description here

I already tried many things, "npm cache clean", reinstall node, reinstall ionic, start/stop nodejs process. But without any success. As I am not finding anyone with the exactly same problem as mine I am asking you guys.

Upvotes: 6

Views: 59556

Answers (15)

Dr NVS
Dr NVS

Reputation: 231

In my case I found : "contains both browserslist and package.json with browsers " So, I deleted the browserlist from the file system. Now the [ERROR] ng has unexpectedly closed (exit code 127)." had gone and running with other errors.

Upvotes: 0

Ali
Ali

Reputation: 1759

run the below command, Proxy can be enabled by default!!:

ionic config unset proxy -g

https://github.com/ionic-team/ionic-cli/issues/4454

Upvotes: 0

Hajaniaina
Hajaniaina

Reputation: 11

Run this code.

export NODE_OPTIONS=--openssl-legacy-provider

Upvotes: 1

Yaham
Yaham

Reputation: 13

It's depend of your error:

[ERROR] ng has unexpectedly closed (exit code 1).

Just tell you, that it can't run the server, you need to watch the error like it told:

The Ionic CLI will exit. Please check any output above for error details.

For me it throw error while in (phase:setup)

Then you just car read it:

throw new Error("Depend of your error")
Error: Depend of your error

After finding this line, you can search in stackoverflow or google how solve the error.

For me it was a missing dependencies, and I just install it:

Error: The target entry-point "@ionic-native/file" has missing dependencies:
- @ionic-native/core

solved with:

npm i @ionic-native/core

Upvotes: 0

vikashjha.tp
vikashjha.tp

Reputation: 45

npm cache clean --force
npm uninstall -g @angular/cli
npm uninstall -g @ionic/cli

npm install -g @angular/cli
npm install -g @ionic/cli

Upvotes: 1

Sibaram Sahu
Sibaram Sahu

Reputation: 1021

install angular first than create ionic project this is solved for me.

Upvotes: 0

Piyush  Jain
Piyush Jain

Reputation: 323

I known your problem was solved but also you can apply the following command
in your terminal

npm cache clean --force
npm uninstall -g @angular/cli
npm uninstall -g @ionic/cli


you can also delete packatges with the alternative path:- C:\Users\user_Name\AppData\Roaming

in Roaming folder delete npm folder it removes all packages which you previously install (angular/ionic etc.)

and now last reinstall all the dependencies

npm install -g @angular/cli
npm install -g @ionic/cli

Upvotes: 0

user9591065
user9591065

Reputation:

Could it be possible that while creating this Ionic project/app it got hint with internet issues or network related trouble which didnt install all the needed dependencies?

Try creating a branch new ionic project then cd into it and run ionic serve to see if all goes smooth.

Good luck

Upvotes: 0

eda
eda

Reputation: 11

It requires to Specify the type Run the below command

ionic start myApp tabs --type=ionic1

Upvotes: 1

RRR
RRR

Reputation: 131

1: open your project root folder

2: delete node_modules folder

3: run npm install

This solution worked... i hope this helps!

Upvotes: 2

Tahseen Quraishi
Tahseen Quraishi

Reputation: 1553

at first you have to delete node module folder from your project.

then run below command

npm cache clean --force

after that run

npm i

finally, now you can run

ionic serve

Upvotes: 0

Prakash
Prakash

Reputation: 89

Re-install below package...

npm install @ionic/app-scripts@latest --save-dev

And just change PATHEXT if there is space or ; at last then remove it

Upvotes: 3

Afsha Mohammed
Afsha Mohammed

Reputation: 11

I got error when I run my ionic serve, the ionic command line interface (CLI) will exit.
So first I delete my node_modules folder, but it is not resolved.

Finally, it is resolved to run the command line below I mentioned:

npm install @ionic/app-scripts@latest --save-dev

Upvotes: 1

David Rocha
David Rocha

Reputation: 549

The problem was my version of NodeJS and JDK.

I used "nvm use 8.12.0" to point to supported node version. Also I have to change the version of my JDK, I used openJDK 8.

Upvotes: 1

LukeVenter
LukeVenter

Reputation: 509

I found that if I copied my files from the original folder they were created in, into a new folder, then I got that error. But if I served it from it's original folder, it worked first time.

I also made sure I had the latest npm and node installed.

Upvotes: 0

Related Questions