13

I used to have Angular CLI, but I mistakenly installed it again with

npm install -g angular-cli

And now when I run ng serve it complains:

It seems like you're using a project generated using an old version of the Angular CLI.

The latest CLI now uses webpack and includes a lot of improvements, include a simpler workflow, a faster build and smaller bundles.

To get more info, including a step-by-step guide to upgrade the CLI, follow this link: https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.12

When I try to create a new project using ng new in another directory, it complains that:

Cannot find module 'reflect-metadata'

So what is the problem?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Sal-laS
  • 10,023
  • 25
  • 90
  • 156
  • 3
    Try `npm uninstall -g angular-cli` & `npm cache clear`. Then install the global CLI again. – Yuri Sep 29 '16 at 15:31
  • doesn't work. I tried it – Sal-laS Sep 29 '16 at 15:40
  • I had the same issue after updating git for windows. Reinstalling CLI package helped. Don't forget restart your console after changing system PATH variable. – Arek Kostrzeba Sep 10 '18 at 21:11
  • Please make the local and global versions of the cli same. – gaya3_96 Feb 19 '21 at 01:16
  • I have all the required sw installed and can verify by checking their versions, but `ng serve` still does not work and only shows a new prompt again. What do I do? This happened out of the blue, on a project that I have been working on for a while now... – CatarinaRuna Aug 09 '21 at 08:20

14 Answers14

13

The key is to have both global and local Angular-cli versions the same.

Let's say we want to fixate it to eg. 1.0.0-beta.15.

So you can try to fixate the version in npm install -g angular-cli@1.0.0-beta.15 and in your package.json fixate it to the same version: "angular-cli": "1.0.0-beta.15". Then run npm install --save-dev.

Currently Angular CLI can be found on NPM under @angular/cli instead of angular-cli. Here are links to documentation how to uninstall old and install the latest version of CLI.

Arek Kostrzeba
  • 529
  • 1
  • 7
  • 21
Yuri
  • 3,809
  • 1
  • 23
  • 42
  • Well, you have to have both - one inside your project's `node_modules` and the other globally in your *Node.js* `node_modules`. The CLI works this way. – Yuri Sep 29 '16 at 16:13
  • You can fixate your Angular framework version in your `package.json` to the RC5 by removing the `^` chars in front of the version string - if you want to. – Yuri Sep 29 '16 at 16:15
12

I think you are probably using an old version of Angular CLI. You can reinstall the latest version by the following command.

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
YoongKang Lim
  • 526
  • 5
  • 16
8

Try commands

npm start ng s

or

npm start
Lixas
  • 5,997
  • 2
  • 22
  • 41
  • Check you are not serving a blank page :-) – Wilkoteq Jul 19 '18 at 14:35
  • This helped me troubleshoot. When I ran 'npm start', it showed that I was getting an "Access is denied" error when trying to run the ng command. Turns out my company was blocking the ng.exe. – Francisco d'Anconia Aug 05 '21 at 17:43
  • An explanation would be in order. E.g., what is it supposed to accomplish? Why is it necessary? What is the idea/gist? Under what circumstances should it be used? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/51422389/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 14 '22 at 18:15
7

I was also facing this, but now it’s resolved:

Put this line in file package.json for start:

"start": "ng serve --host 0.0.0.0 --port 4201"
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
nikhil kumar
  • 81
  • 2
  • 4
4

On Ubuntu, firstly do:

npm install --save-dev

Try:

sudo npm install -g @angular/cli

and then try:

ng serve

This will work 100%.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
shrikant joshi
  • 414
  • 3
  • 12
  • global installation with "sudo" is not recommended, no – Fikret Jan 20 '21 at 08:00
  • What version of Ubuntu was it tested on? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/55357961/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 14 '22 at 18:26
2

I used ng serve --open, and it worked for me.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Steve
  • 9,577
  • 15
  • 86
  • 136
2

Try the below code. This works for me.

npm uninstall -g angular-cli
npm install --cache/tmp/empty-cache
ng serve
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0
npm install -g @angular/cli
cd "yourProjectName"
ng serve -o
Flash
  • 864
  • 2
  • 20
  • 41
  • An explanation would be in order. E.g., what is the idea/gist? Does it differ from some standard procedure? Why does it differ? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/55358185/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 14 '22 at 18:28
0

In my case,

I was using a higher version of Angular (8+) which was not compatible with Node.js version v8.11.3. I was even getting exit status code 3. So I installed it using the Windows MSI installer and it upgraded my version of Node.js.

Courtesy - How can I update npm on Windows?.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

I had the same issue. I was using a Linux machine and I solved it by using sudo

Just add sudo before your ng serve command. For example:

sudo ng serve --port 6161
jtate
  • 2,437
  • 7
  • 27
  • 33
0

Switch to your project and try this code:

npm i https://github.com/Qix-/node-error-ex <br/>
npm install <br/>
ng serve --open 
jla
  • 3,111
  • 3
  • 27
  • 39
0

In Ubuntu, follow the following steps:

sudo npm install --save-dev

sudo npm install -g @angular/cli

ng serve

This will definitely work.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
0

It worked for me

  1. Open with Live Server (If Working on Index.html or app.component.html)
  2. Type ng serve --open (In VS Code Terminal)

Changes will be visible on http://localhost:4200/

If you are using VS Code then open whole folder in VS Code.

Code runner won't work - "Code language not supported or defined"

Hope it helps you :)

AtirRH
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 13 '22 at 08:42
-1

I tried literally everything, but this one worked for me:

Go to:

C:\Users\<profile_name>\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

Don't forget ng at the end

Then try:

ng -v (to show the version of ng)

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
  • On [Windows](https://en.wikipedia.org/wiki/Microsoft_Windows), presumably? – Peter Mortensen Jan 14 '22 at 18:20
  • 1
    Why is getting it to ***display the version information*** accomplishing anything? Are there some (positive) side effects to the state of the system by doing this? Isn't there more to this story? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/54069252/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 14 '22 at 18:22
  • This does nothing but output your current ng version to the console. Downvoted. – rmcsharry Jan 27 '22 at 09:36