4

I'm getting the following error after an npm audit fix --force (I know, I know).

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

I'm guessing that I need a project.json file however I can't find a template (or documentation) for that.

Extracts from my package.json:

  "dependencies": {
    "@angular/animations": "^5.0.3",
    "@angular/common": "^5.0.3",
    "@angular/compiler": "^5.0.3",
    "@angular/core": "^5.0.3",
    "@angular/forms": "^5.0.3",
    "@angular/http": "^5.0.3",
    "@angular/platform-browser": "^5.0.3",
    "@angular/platform-browser-dynamic": "^5.0.3",
    "@angular/router": "^5.0.3",

  "devDependencies": {
    "@angular/cli": "^7.2.3",  <-- previously 1.5.4
    "@angular/compiler-cli": "^5.0.3",

(can post full file if needed)

image desc

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • 1
    Do you have the `angular.json` file in your project's root? Or do you have the `.angular-cli.json` file? If you have the latter file, consider updating it with `ng update @angulr/cli` to update the Angular CLI config file. (You should also update your Angular dependencies to v7 - run `ng update @angular/core` to solve that!) – Edric Jan 24 '19 at 12:12
  • Thanks @Edric - I had `angular-cli`, I'll follow those steps! cheers – Allan Bowe Jan 24 '19 at 12:15
  • I tried all the above, uninstalling several packages and `ng update`ing everything, in the end this was the command that worked: `ng update @angular/cli --from=1.7.4 --migrate-only` – Allan Bowe Jan 24 '19 at 12:37

3 Answers3

10

Credit to @dmoore1181 and @Edric for pointing out that the missing file was indeed angular.json and that an upgrade was needed.

Following the advice in this question, I completed the upgrade but still didn't have an angular.json - what did this for me in the end (and also mentioned in the answer to that question) was the following command:

ng update @angular/cli --from=1.7.4 --migrate-only

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
1

Create a new project with ng new and that should create the file you need. Then you can copy it over to your project.

dmoore1181
  • 1,793
  • 1
  • 25
  • 57
  • I tried that but there was no `project.json` - I might be wrong about that file in any case – Allan Bowe Jan 24 '19 at 12:15
  • 1
    @AllanBowe I believe that project.json is for Angular JS (Angular 1.x) and angular.json is for Angular (Angular 2.X and greater). The Angular tag confused me when I was reading your question. – dmoore1181 Jan 24 '19 at 12:20
0

If you have the Nx Console installed, use that to build your project. Or from the command line it is:

npx ng run {app-name}:build
Emi OB
  • 2,814
  • 3
  • 13
  • 29
  • 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 Apr 26 '22 at 08:13