2

I had problems with my dependencies in Angular so i reinstalled it in my project. So, what I did was this:

npm uninstall -g angular-cli
npm cache clean or npm cache verify
npm install -g @angular/cli@latest

rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest
npm install

However now, when trying to use npm start or ng serve, this happens

The serve command requires to be run in an Angular project, but a project definition could not be found.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular@0.0.0 start: `ng serve`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular@0.0.0 start script.

additional to that, when trying the npm install command I get strange warnings:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

audited 7337 packages in 4.116s
found 20 vulnerabilities (3 low, 14 moderate, 3 high)

It worked before uninstalling (except for the dependencies) so i'm getting really frustrated.

First thing I found googling this problem of course was

Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found

but after doing this, the problem still consisted.

How can I reinstall Angular correctly?

J.Doe
  • 586
  • 2
  • 8
  • 30
  • are you running npm install in correct folder? Kinda sounds like you dont. – AT82 Sep 24 '19 at 12:25
  • Possible duplicate of [Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found](https://stackoverflow.com/questions/53096996/angular-cli-error-the-serve-command-requires-to-be-run-in-an-angular-project-b) – 31piy Sep 24 '19 at 12:28
  • @AJT82 It's definitely in the right folder – J.Doe Sep 24 '19 at 12:32
  • Yeah, that error is often present when you run the final `npm install` and `ng serve` **outside the project folder**, like error kind of suggests, but if you are indeed in the app folder, it's something else :) – AT82 Sep 24 '19 at 12:41

2 Answers2

8

Try this,

    npm uninstall -g angular-cli
    npm uninstall -g @angular/cli
    npm cache clean
    npm install -g @angular/cli@latest

Then when it gets done successfully you may try:

ng --version

Dixit Savaliya
  • 413
  • 3
  • 7
  • I tried this and still got the same error. When running ng --version i get this 'Angular CLI: 8.3.5 Node: 12.10.0 OS: linux x64 Angular: 5.2.11' – J.Doe Sep 24 '19 at 12:31
  • 1
    try this command, npm install --no-optional --no-shrinkwrap --no-package-lock – Dixit Savaliya Sep 24 '19 at 12:37
  • Okay with this, the error changed to Module '"../../node_modules/@angular/core/core"' has no exported member 'Component'. – J.Doe Sep 24 '19 at 12:43
  • which was solved by rm -rf node_modules/ npm install, your answer is the correct one. – J.Doe Sep 24 '19 at 12:48
  • After all this I'm still getting: This version of CLI is only compatible with Angular versions ^14.0.0, but Angular version 16.2.1 was found instead. – Yster Aug 22 '23 at 13:43
0

Note that there has been an update to checking the version.

OLD: ng --version

NOW: ng version

As of 2-AUG-2022

plm
  • 198
  • 1
  • 8