简体   繁体   中英

After upgrading my Angular app from v7 to v8 ng serve is no longer able to find the project to start it up

I have a project that I have upgraded from Angular 7.2 to Angular 8 and after upgrading the ng serve command fails to be able to launch the app. The ng serve command reports that it is unable to find the app.

I read thought the documentation for angular and the angular.json file. The name of the project has not changed. other than updates performed by the ng upgrade command. When I check the logs it reports that the project does not exist.

I have tried "ng serve" and "ng server publicfrontend" with the angular.json file given.

angular.json file

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "publicfrontend": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon",
              "src/favicon.ico",
              "src/manifest.json"
            ],
            "styles": [
              "node_modules/bootstrap/scss/bootstrap.scss",
              "node_modules/font-awesome/css/font-awesome.css",
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true,
              "ngswConfigPath": "src/ngsw-config.json",
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "devserv": {
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": false,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "angular:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [],
            "styles": [
              "node_modules/font-awesome/css/font-awesome.css",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "src/styles.css"
            ],
            "assets": ["src/assets", "src/favicon", "src/favicon.ico"]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/publicfrontend-server",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "sourceMap": false,
              "optimization": {
                "scripts": false,
                "styles": true
              }
            }
          }
        },
        "app-shell": {
          "builder": "@angular-devkit/build-angular:app-shell",
          "options": {
            "browserTarget": "publicfrontend:build",
            "serverTarget": "publicfrontend:server",
            "route": "app-shell=path"
          },
          "configurations": {
            "production": {
              "browserTarget": "publicfrontend:build:production",
              "serverTarget": "publicfrontend:server:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "publicfrontend",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}


Erics-MacBook-Pro:PublicFrontend naujocke$ ng serve
An unhandled exception occurred: Project does not exist.
See "/private/var/folders/dh/c9j6szpn72g1l1vfkcfb3kyh0000gp/T/ng-6HErtU/angular-errors.log" for further details.

This is the output of the log file.

[error] Error: Project does not exist.
    at WorkspaceNodeModulesArchitectHost.findProjectTarget (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:94:23)
    at WorkspaceNodeModulesArchitectHost.getOptionsForTarget (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:66:33)
    at core_1.experimental.jobs.createJobHandler.name (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/src/architect.js:171:21)
    at Observable._subscribe (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/@angular-devkit/core/src/experimental/jobs/create-job-handler.js:91:26)
    at Observable._trySubscribe (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:44:25)
    at Observable.subscribe (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:30:22)
    at /Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/util/subscribeTo.js:22:31
    at Object.subscribeToResult (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/util/subscribeToResult.js:10:45)
    at SwitchMapSubscriber._innerSub (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/operators/switchMap.js:65:54)
    at SwitchMapSubscriber._next (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/operators/switchMap.js:55:14)
    at SwitchMapSubscriber.Subscriber.next (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Subscriber.js:66:18)
    at SafeSubscriber.__tryOrUnsub (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:207:16)
    at SafeSubscriber.next (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:145:22)
    at Subscriber._next (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:89:26)
    at Subscriber.next (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular/cli/node_modules/rxjs/internal/Subscriber.js:66:18)
    at SafeSubscriber.__tryOrUnsub (/Users/naujocke/Wakanda/solutions/CoronersOffice/PublicFrontend/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Subscriber.js:207:16

There is a problem at your browserTarget. The target must point to the project, not to Angular.

Solution: Change the browserTarget to your project will solve the problem

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "browserTarget": "publicfrontend:build"
  },
  "configurations": {
    "production": {
      "browserTarget": "publicfrontend:build:production"
    }
  }
},
"extract-i18n": {
  "builder": "@angular-devkit/build-angular:extract-i18n",
  "options": {
    "browserTarget": "publicfrontend:build"
  }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM