4

Problem

I create asp.net core with angular 6 application in visual studio 2017 and application is working locally perfectly fine. but when I tried to deploy it to cloud it shows me this error.

AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: 'npm' is not recognized as an internal or external command

I already searched this error but my error remains after applying this answer 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"
}

Package.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"
  }
}

image

enter image description here

Malik Kashmiri
  • 5,741
  • 11
  • 44
  • 80
  • i am having the same error while publishing angular app with .net core 2.1 Did you figure out something ? – Johar Zaman Sep 07 '18 at 20:47
  • I create a ticket on azure but no success applied may solutions – Malik Kashmiri Sep 08 '18 at 09:14
  • 3
    I have figured it out. Btw the problem was, i have copied already built angular project by someone into .net core app. Although it was working fine in local. In angular.json file the name of project was of old project instead of new project. I replaced old name with new one and it worked. – Johar Zaman Sep 08 '18 at 23:32

2 Answers2

0

For me, problem was - IIS selected in Launch. (Project Properties - > Debug Tab). After selecting IIS Express solved the issue for me.

Harshad Raval
  • 79
  • 2
  • 10
0

Your problem is probably your "ASPNETCORE_ENVIRONMENT" variable in Development enviroment. If you look your Startup.cs file, you will find this lines:

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

When you upload that code to a server with the developmen variable, the angular CLI cannot be launched a second time, so it crashes and gives that error message. You have 2 options, or you delete this:

 spa.UseAngularCliServer(npmScript: "start");

or you can substitute it for:

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

I recommend this second option, since if you use the first one, the application will stop working locally.