发生未处理的异常:项目“ app”不存在。离子发球后出现此错误

时间:2020-09-29 11:35:32

标签: angular ionic-framework

起初我使用命令:

ng add @ionic/angular

要将ionic添加到我的Angular 7项目中。

正如标题所述,我遇到此错误:发生未处理的异常:项目“ app”不存在 当我尝试通过命令为Angular7 / Ionic 4项目提供服务时:

ionic serve

我了解到导致此问题的项目名称不一致,但对我来说似乎不错。 这是我的相关文件:

angular.json

    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "Angular7": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/Angular7",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              {
                "glob": "**/*.svg",
                "input": "node_modules/ionicons/dist/ionicons/svg",
                "output": "./svg"
              }
            ],
            "styles": [
              "src/styles.css",
              {
                "input": "node_modules/@ionic/angular/css/normalize.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/structure.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/typography.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/core.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/padding.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/float-elements.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/text-alignment.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/text-transformation.css"
              },
              {
                "input": "node_modules/@ionic/angular/css/flex-utils.css"
              },
              {
                "input": "src/theme/variables.css"
              }
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "Angular7:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "Angular7:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "Angular7:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "Angular7:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "Angular7:serve:production"
            }
          }
        },
        "ionic-cordova-serve": {
          "builder": "@ionic/angular-toolkit:cordova-serve",
          "options": {
            "cordovaBuildTarget": "Angular7:ionic-cordova-build",
            "devServerTarget": "Angular7:serve"
          },
          "configurations": {
            "production": {
              "cordovaBuildTarget": "Angular7:ionic-cordova-build:production",
              "devServerTarget": "Angular7:serve:production"
            }
          }
        },
        "ionic-cordova-build": {
          "builder": "@ionic/angular-toolkit:cordova-build",
          "options": {
            "browserTarget": "Angular7:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "Angular7:build:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "Angular7"
}

package.json:

{
  "name": "angular7",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~10.1.2",
    "@angular/common": "~10.1.2",
    "@angular/compiler": "~10.1.2",
    "@angular/core": "~10.1.2",
    "@angular/forms": "~10.1.2",
    "@angular/platform-browser": "~10.1.2",
    "@angular/platform-browser-dynamic": "~10.1.2",
    "@angular/router": "~10.1.2",
    "@ionic/angular": "^5.3.4",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.2",
    "@angular/cli": "~10.1.2",
    "@angular/compiler-cli": "~10.1.2",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2",
    "@ionic/angular-toolkit": "latest"
  }
}

ionic.config.json

{
  "name": "Angular7",
  "integrations": {},
  "type": "angular"
}

我不知道该怎么办

2 个答案:

答案 0 :(得分:1)

问题的原因是默认项目及其构建的名称。由于某种原因,Ionic在解决它方面存在问题。我没有在docs中找到直接答案,但是使用多项目配置似乎可行。如果您将ionic.config.json更改为:

{
  "defaultProject": "Angular7",
  "projects": {
    "Angular7": {
      "name": "Angular7",
      "integrations": {},
      "type": "angular"
    }
  }
}

然后它应该可以使用您更改的名称。

答案 1 :(得分:0)

Jakubs的回答完全解决了我的问题。在浏览此页面之前,我已经花了3天时间动脑筋。现在我想知道为什么Ionic在配置文件中需要嵌套的名称标签?

{ “ defaultProject”:“ Angular7”, “项目”:{ “ Angular7”:{ “ name”:“ Angular7”, “集成”:{}, “ type”:“角度” } } }