angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng serve command not working

Open lukejoliat opened this issue 9 years ago • 37 comments

Please provide us with the following information:

OS?

MacOS Sierra

Versions.

angular-cli: 1.0.0-beta.28.3 node: 7.4.0 os: darwin x64

Repro Steps

After running 'ng serve' in an app created by 'ng new...' I get this output from the console:

`As a forewarning, we are moving the CLI npm package to "@angular/cli" with the next release,
which will only support Node 6.9 and greater. This package will be officially deprecated
shortly after.

To disable this warning use "ng set --global warnings.packageDeprecation=false".

** NG Live Development Server is running on http://localhost:4200. **
Hash: b17a9b8b2eeffaf40894                                                    e Time: 6294ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 222 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.map (main) 3.94 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.64 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.`

But when I navigate to the localhost:4200 in my browser, I get this message:

This site can’t be reached

localhost refused to connect.

Which to me indicates that there is nothing running on that port, contrary to what the output in the console says. If I try running in different ports, I get the same result. No error messages, just no server.

Any help would be really appreciated.


Thanks! We'll be in touch soon.

lukejoliat avatar Feb 02 '17 19:02 lukejoliat

I can confirm that it now works for me.

I did un unistall and re-install for the npm angular-cli module

gotofritz avatar Feb 03 '17 22:02 gotofritz

@lukejoliat if you have a Windows machine, could you try reinstalling the CLI? Let me know if it's fixed.

hansl avatar Feb 04 '17 06:02 hansl

Live reload doesn't work for changes in .ts files. It works on html.

@angular/cli: 1.0.0-beta.30
node: 6.9.5
os: win32 x64
@angular/common: 2.4.6
@angular/compiler: 2.4.6
@angular/core: 2.4.6
@angular/flex-layout: 2.0.0-beta.4
@angular/forms: 2.4.6
@angular/http: 2.4.6
@angular/material: 2.0.0-beta.1
@angular/platform-browser: 2.4.6
@angular/platform-browser-dynamic: 2.4.6
@angular/router: 3.4.6
@angular/cli: 1.0.0-beta.30
@angular/compiler-cli: 2.4.6
@ngtools/webpack: 1.2.7

kilgarenone avatar Feb 06 '17 02:02 kilgarenone

@kilgarenone a new version of @ngtools/webpack has been released recently.

Can you remove node_modules and npm install and see if that fixes it?

beeman avatar Feb 06 '17 02:02 beeman

Cool.. @beeman Thank you.. It works

delete "node_modules" npm install

pnsvinodkumar avatar Feb 09 '17 04:02 pnsvinodkumar

ng serve not working plz help me. error

KISHANSHUKLA avatar Feb 15 '17 10:02 KISHANSHUKLA

for any of you guys who still have the problem, you need to re-install angular-cli through this command

npm install -g @angular/cli

or if you are using the old cli, you can just updated by this command

ng update

lordnino avatar Feb 15 '17 23:02 lordnino

Thanks man..

KISHANSHUKLA avatar Feb 17 '17 19:02 KISHANSHUKLA

@lordnino thanx for you comment, fix my problem with angular-cli!!!!

aarondiazr avatar Feb 27 '17 20:02 aarondiazr

Closing as the original poster has identified it's a local setup problem (https://github.com/angular/angular-cli/issues/4368#issuecomment-277152176).

Most of the comments here are also completely unrelated to the original one.

filipesilva avatar Mar 09 '17 11:03 filipesilva

At last find the solution for ng command is not working issue ,Find the solution below http://itechiesol.blogspot.com/2017/07/angular-cli-ng-command-is-not-working.html

naru6be avatar Jul 22 '17 13:07 naru6be

69% building modules 697/701 modules 4 active ...es@angular\common\src\facade\ 69% building modules 697/702 modules 5 active ...gular\common\src\facade\collec 69% building modules 698/702 modules 4 active ...gular\common\src\facade\collec 69% building modules 699/702 modules 3 active ...gular\common\src\facade\collec 69% building modules 700/702 modules 2 active ...gular\common\src\facade\collec 69% building modules 701/702 modules 1 active ...gular\common\src\facade\collec 69% building modules 702/703 modules 1 active ...@angular\common\src\facade\erHash: a0a14da72a6852660afd Time: 11803ms chunk {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 234 kB {4} [initial] [rendered] chunk {1} main.bundle.js, main.bundle.map (main) 4.04 kB {3} [initial] [rendered] chunk {2} styles.bundle.js, styles.bundle.map (styles) 9.71 kB {4} [initial] [rendered] chunk {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.63 MB [initial] [rendered] chunk {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered] webpack: Compiled successfully.

Can anyone help me? when i start to write "ng-serve/server" the app doesn't launch

ilkin93 avatar Jan 29 '18 09:01 ilkin93

As of March 2018, this problem has resurfaced. This shell script reproduces the problem:

# fail.sh
npm install -g @angular/cli
ng new dir
cd dir
npm install
ng serve --open

My browsers (Safari 11.0.3 and Chrome 65.0.3325.162) both claim that "the server unexpectedly dropped the connection".

System

macOS High Sierra 10.13.3

$ uname -a
 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
$ node --version
v9.4.0
$ ng version
Angular CLI: 1.7.3
Node: 9.4.0
OS: darwin x64
Angular:
...

Debugging steps

The port, (4200) is correctly bound to node:

$ lsof -i :4200
COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    45087 developer   19u  IPv4 0x8ad892271debf961      0t0  TCP localhost:4200 (LISTEN)

Both curl and Postman manage to load the bundle from ng correctly:

$ curl -L localhost:4200/
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
</head>
<body>
  <app-root></app-root>
  ...
</html>

Safari 11.0.3 and Chrome 65.0.3325.162 both claim that "the server unexpectedly dropped the connection". screen shot 2018-03-18 at 3 57 12 pm

Why are my browsers unable to connect to the Angular dev server, when curl and Postman can?

Update

Running ng serve --host 0.0.0.0 and visiting 0.0.0.0:4200 solves this. I still do not understand why Chrome and Safari dislike localhost:4200.

AnalyzePlatypus avatar Mar 18 '18 14:03 AnalyzePlatypus

thanks @lordnino problem solved 👍

jcotilla avatar Mar 21 '18 19:03 jcotilla

@lordnino Thanks mate! simple npm install -g @angular/cli did the job...

playnox avatar May 02 '18 03:05 playnox

As of March 2018, this problem has resurfaced. This shell script reproduces the problem:

# fail.sh
npm install -g @angular/cli
ng new dir
cd dir
npm install
ng serve --open

My browsers (Safari 11.0.3 and Chrome 65.0.3325.162) both claim that "the server unexpectedly dropped the connection".

System

macOS High Sierra 10.13.3

$ uname -a
 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
$ node --version
v9.4.0
$ ng version
Angular CLI: 1.7.3
Node: 9.4.0
OS: darwin x64
Angular:
...

Debugging steps

The port, (4200) is correctly bound to node:

$ lsof -i :4200
COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    45087 developer   19u  IPv4 0x8ad892271debf961      0t0  TCP localhost:4200 (LISTEN)

Both curl and Postman manage to load the bundle from ng correctly:

$ curl -L localhost:4200/
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
</head>
<body>
  <app-root></app-root>
  ...
</html>

Safari 11.0.3 and Chrome 65.0.3325.162 both claim that "the server unexpectedly dropped the connection". screen shot 2018-03-18 at 3 57 12 pm

Why are my browsers unable to connect to the Angular dev server, when curl and Postman can?

Update

Running ng serve --host 0.0.0.0 and visiting 0.0.0.0:4200 solves this. I still do not understand why Chrome and Safari dislike localhost:4200.

Visiting http://127.0.0.1:4200/ worked for me.

sudoanupriya avatar Oct 01 '18 10:10 sudoanupriya

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.