0

I have update my angular and I get the following error:

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

I have done already following:

D:\IntelliJProjects\springboottests\src\main\frontend2>ng update @angular/cli --migrate-only
    Package not installed: "@angular/cli". Skipping.
    We analyzed your package.json and everything seems to be in order. Good work!

D:\IntelliJProjects\springboottests\src\main\frontend2>ng serve
The serve command requires to be run in an Angular project, but a project definition could not be found.

D:\IntelliJProjects\springboottests\src\main\frontend2>

I am in the folder with package.json and angular-cli.json.

I have tried already suggestions from stackoverflow, but nothing helped.

My version:

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.12.2 (cli-only)
@angular-devkit/core         7.2.2 (cli-only)
@angular-devkit/schematics   7.2.2 (cli-only)
@angular/tsc-wrapped         0.5.2
@ngtools/json-schema         1.1.0
@ngtools/webpack             1.10.2
@schematics/angular          7.2.2 (cli-only)
@schematics/update           0.12.2 (cli-only)
rxjs                         6.3.3
typescript                   3.2.4
webpack                      2.2.0

any help ?

mcfly soft
  • 11,289
  • 26
  • 98
  • 202
  • Did you change Node.js version on your system ? – Leo Jan 18 '19 at 13:29
  • Not sure but I guess. I have updated with : ng update --all – mcfly soft Jan 18 '19 at 13:30
  • are you able to create new project using cli command ? – Raja Mohamed Jan 18 '19 at 13:48
  • `The serve command requires to be run in an Angular project, but a project definition could not be found.` it is literally telling you what the problem is. This is not an Angular project. – Reactgular Jan 18 '19 at 13:52
  • I can read that too :-) But I have my angular project running before the upgrade. I can see the .json files in the folder. So there must something chagend. – mcfly soft Jan 18 '19 at 13:55
  • I have added a empty angular.json and I get another error that it is empty. It seems they changed the projectfile name. How can I migrate that file ? just move it ? – mcfly soft Jan 18 '19 at 15:38

2 Answers2

1

Make sure you are running the ng serve command from the angular application root folder. If it is already the case then may be try this:

  • Get your angular cli current version with ng -v
  • ng update @angular/cli --migrate-only --from=[angular cli version]

from this SO thread

Leo
  • 741
  • 6
  • 14
  • I am in the folder of package.json. I did the same you suggested, but it just says. "We analyzed your package.json and everything seems to be in order. Good work!" . Then ng server -> "The serve command requires to be run in an Angular project, but a project definition could not be found." – mcfly soft Jan 18 '19 at 13:54
  • In the snippet from your question, you didn't specify any version: `ng update @angular/cli --migrate-only` – Leo Jan 18 '19 at 14:03
  • I have done with "ng update @angular/cli --migrate-only --from=7.2.2", but still the same problem. – mcfly soft Jan 18 '19 at 15:34
  • I have added a empty angular.json and I get another error that it is empty. It seems they changed the projectfile name. How can I migrate that file ? just move it ? – mcfly soft Jan 18 '19 at 15:37
  • My guess is that the first time you updated the angular cli you didn't specify the version for `--from` option, and your new angular cli version use `angular.json` instead of `angular-cli.json`, do you remember your angular cli version before first update ? – Leo Jan 18 '19 at 15:55
  • I guess you are right. That was my fault. So I have to setup from scratch and copy my code into the new project, right ? – mcfly soft Jan 19 '19 at 16:54
  • I would certainly try. – Leo Jan 21 '19 at 08:07
0

it's because of angular.json file just run ng update @angular/cli

Ali Safari
  • 31
  • 2