【问题标题】:Asp.Net Core Angular 6 Error : The NPM script 'start' exited without indicating that the Angular CLI was listening for requestsAsp.Net Core Angular 6 错误:NPM 脚本“开始”退出,但未指示 Angular CLI 正在侦听请求
【发布时间】:2022-01-10 14:03:15
【问题描述】:

问题

我在 Visual Studio 2017 中使用 Angular 6 应用程序创建了 asp.net 核心,并且应用程序在本地运行得非常好。但是当我尝试将其部署到云时,它显示了这个错误。

AggregateException:发生一个或多个错误。 (发生了一个或多个错误。(NPM 脚本 'start' 退出但没有表明 Angular CLI 正在侦听请求。错误输出是:'npm' is not Recognized as an internal or external command

我已经搜索过这个错误,但应用这个答案后我的错误仍然存​​在 other solution

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ClientApp": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/ClientApp",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "src/assets/js/azure-storage.blob.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ClientApp:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ClientApp:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ClientApp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "src/assets/js/azure-storage.blob.min.js"
            ],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "ClientApp-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ClientApp:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "ClientApp:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "ClientApp"
}

包.json

{
  "name": "client-app",
  "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": "^6.1.0",
    "@angular/cdk": "^6.4.5",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "ngx-toastr": "^8.7.3",
    "@angular/material": "^6.0.1",
    "firebase": "^5.4.0",
    "angularfire2": "^5.0.0-rc.11",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "devextreme": "^18.1.4",
    "devextreme-angular": "^18.1.4",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "jszip": "^3.1.5",
    "ng2-file-upload": "^1.3.0",
    "time-ago-pipe": "^1.3.2",
    "angular-select2-component": "^1.1.4",
    "angular2-multiselect-dropdown": "^2.9.0",
    "angular4-carousel": "^3.1.8",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "^6.1.5",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

图片

【问题讨论】:

  • 我在使用 .net core 2.1 发布 Angular 应用程序时遇到了同样的错误你发现了什么吗?
  • 我在 azure 上创建了一张票,但没有成功应用可能的解决方案
  • 我已经想通了。顺便说一句,问题是,我已经将某人已经构建的 Angular 项目复制到了 .net 核心应用程序中。尽管它在本地运行良好。在 angular.json 文件中,项目的名称是旧项目而不是新项目。我用新名字替换了旧名字,它起作用了。

标签: angular6 asp.net-core-2.1


【解决方案1】:

对我来说,问题是 - 在 Launch 中选择了 IIS。 (项目属性 - > 调试选项卡)。 选择 IIS Express 后为我解决了这个问题。

【讨论】:

    【解决方案2】:

    您的问题可能是您在开发环境中的“ASPNETCORE_ENVIRONMENT”变量。如果您查看 Startup.cs 文件,您会发现以下几行:

    if (env.IsDevelopment())
    {
       spa.UseAngularCliServer(npmScript: "start");
    }
    

    当您使用 developmentmen 变量将该代码上传到服务器时,无法再次启动 angular CLI,因此它会崩溃并给出错误消息。你有 2 个选项,或者你删除这个:

     spa.UseAngularCliServer(npmScript: "start");
    

    或者您可以将其替换为:

     #if DEBUG
        spa.UseAngularCliServer(npmScript: "start");
     #endif 
    

    我推荐第二个选项,因为如果您使用第一个选项,应用程序将在本地停止工作。

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2020-11-22
      • 2018-12-22
      相关资源
      最近更新 更多