Resolving NPM Script 'start' Exit Error After Angular CLI Upgrade: Analysis of --extractCss Parameter Issue

Dec 08, 2025 · Programming · 11 views · 7.8

Keywords: Angular CLI | .NET Core | NPM script error | package.json configuration | SpaServices

Abstract: This article provides an in-depth analysis of the NPM script 'start' exit error that occurs after upgrading Angular CLI in .NET Core and Angular SPA projects. The core issue lies in the --extractCss parameter no longer being supported in Angular 6, causing the Angular CLI to fail during startup. The article details the error causes, offers solutions by modifying the package.json file to remove this parameter, and explores alternative approaches such as manual Angular CLI server startup. Through code examples and configuration explanations, it helps developers quickly identify and resolve such integration environment issues.

When developing .NET Core and Angular single-page applications (SPAs), many developers encounter a common yet confusing error: when attempting to start the application via dotnet run, the system throws an InvalidOperationException with the message “The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extractCss'.” This error typically occurs after upgrading Angular CLI, especially during transitions from Angular 5 to Angular 6. This article delves into the root causes of this issue from a technical perspective and presents multiple solutions.

Error Cause Analysis

The core of this error stems from parameter configuration issues due to Angular CLI version incompatibility. In Angular 5, the --extract-css parameter controlled CSS file extraction, but in Angular 6, this parameter has been deprecated or is no longer supported. When upgrading projects created with the dotnet new angular template, the script configurations in the package.json file may retain parameters from older versions, leading the Angular CLI to fail to recognize them and throw an error.

Specifically, in the package.json file, the default script configuration might appear as follows:

"scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",
    "build": "ng build --extract-css",
    // other scripts...
}

Here, the --extract-css parameter is no longer valid in Angular 6's CLI, so when .NET Core attempts to start the Angular development server via SpaServices, the NPM script exits due to the parameter error, triggering an exception. The error stack trace shows that Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware detects the script exit during server startup and throws the corresponding exception.

Primary Solution: Modify package.json

Based on best practices and community feedback, the most direct solution is to modify the package.json file by removing the unsupported --extract-css parameter. The specific steps are as follows:

  1. Open the package.json file in the project root directory.
  2. Locate the scripts section and find the start and build scripts.
  3. Remove the --extract-css parameter from these two scripts. The modified configuration should look like this:
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    // other scripts remain unchanged
}

This modification ensures that the Angular CLI can correctly parse script parameters and start the development server normally. After making this change, rerun dotnet run, and the error is usually resolved. This method is simple and effective, making it the preferred solution for handling such version compatibility issues.

Supplementary Solutions and In-Depth Discussion

Beyond modifying package.json, other methods can address this issue, particularly in edge cases.

Manually Start the Angular CLI Server

If the above modification does not resolve the problem, or if developers prefer more control over the server startup process, they can manually start the Angular CLI server and integrate it with the .NET Core application via proxy configuration. The specific steps are:

  1. Navigate to the ClientApp directory of the project (typically where the Angular frontend code resides) in the command line.
  2. Run the ng serve command to start the Angular development server (default listening on port 4200).
  3. In the Startup.cs file of the .NET Core project, locate the Spa configuration section and replace spa.UseAngularCliServer() with:
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");

This way, the .NET Core application will proxy requests to the manually started Angular server, bypassing the automatic startup script error. This approach is particularly useful during debugging, as it allows independent control over frontend and backend server startups.

Environment Configuration Adjustments

In some deployment environments, such as Azure Web App, environment variables may affect application behavior. For example, setting ASPNETCORE_ENVIRONMENT=Development might trigger specific logic in SpaServices, leading to errors. In such cases, removing or adjusting this environment variable may help resolve the issue. However, note that this is usually not the root cause, and modifying package.json should be prioritized.

Use npm audit fix

Another auxiliary method is to run the npm audit fix command, which automatically fixes known vulnerabilities in package dependencies and may indirectly resolve configuration issues. Executing this command in the ClientApp directory can help update or adjust dependencies, thereby improving compatibility. However, this method has limited effectiveness and should not be the primary solution.

Code Examples and Configuration Details

To better understand the solutions, here is a complete package.json modification example, demonstrating the correct configuration after upgrading from Angular 5 to Angular 6:

{
  "name": "my-angular-app",
  "version": "1.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.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "^6.0.0",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/language-service": "^6.0.0",
    "@types/node": "^8.9.4",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

The key points are that the start and build scripts no longer include the --extract-css parameter, and dependencies are updated to Angular 6-compatible versions. Additionally, ensure that the @angular/cli version is 6.x to avoid other potential issues.

Summary and Best Practices

The core of resolving the “The NPM script 'start' exited without indicating that the Angular CLI was listening for requests” error lies in identifying and handling version-incompatible configuration parameters. By modifying the package.json file to remove the --extract-css parameter, most cases can be quickly resolved. If the problem persists, consider manually starting the Angular server or checking environment configurations.

When upgrading Angular projects, it is advisable to follow official upgrade guides and carefully review configuration file changes. Regularly updating dependencies and running npm audit fix also helps maintain project health. For .NET Core and Angular integration development, understanding how SpaServices works and its configuration options will enable developers to debug and deploy applications more efficiently.

Through the analysis and solutions provided in this article, developers should be able to confidently handle similar errors and ensure smooth application operation. Remember, configuration adjustments during version upgrades are common challenges, but with systematic approaches and community resources, these issues can be effectively resolved.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.