You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular项目执行npm start报错:退出状态3,启动脚本执行失败

Angular项目npm start/ng serve进程终止问题排查

我是Angular新手,接手现有项目完成配置后,执行npm start时进程突然终止,ng serve运行失败,自行排查未找到解决办法。

环境信息

  • npm版本:6.14.11
  • node版本:v14.15.5

项目依赖配置(package.json)

"dependencies": {
    "@angular/animations": "^11.0.3",
    "@angular/cdk": "^11.0.1",
    "@angular/common": "~11.0.3",
    "@angular/compiler": "~11.0.3",
    "@angular/core": "~11.0.3",
    "@angular/flex-layout": "^11.0.0-beta.33",
    "@angular/forms": "~11.0.3",
    "@angular/material": "^11.0.1",
    "@angular/platform-browser": "~11.0.3",
    "@angular/platform-browser-dynamic": "~11.0.3",
    "@angular/platform-server": "~11.0.3",
    "@angular/router": "~11.0.3",
    "@angular/service-worker": "^11.0.3",
    "@ngx-prism/core": "^2.0.1",
    "@syncfusion/ej2-angular-richtexteditor": "^18.3.52",
    "@types/prismjs": "^1.16.2",
    "@types/socket.io-client": "^1.4.34",
    "angular-http-server": "^1.9.0",
    "app-root-path": "^3.0.0",
    "chart.js": "^2.9.4",
    "compodoc": "0.0.41",
    "core-js": "^3.8.0",
    "dotenv": "^8.2.0",
    "http-server": "^0.12.3",
    "http-status": "^1.5.0",
    "jquery": "^3.5.1",
    "ngx-captcha": "^8.0.1",
    "ngx-countdown": "^11.0.0",
    "ngx-countdown-timer": "^0.2.0",
    "ngx-drag-drop": "^2.0.0",
    "ngx-json-viewer": "^2.4.0",
    "ngx-mat-select-search": "^3.1.4",
    "ngx-pipes": "^2.7.5",
    "ngx-socket-io": "^3.2.0",
    "prismjs": "^1.22.0",
    "rxjs": "^6.6.3",
    "rxjs-compat": "^6.6.3",
    "socket.io-client": "^3.0.3",
    "xls": "^0.5.1",
    "xlsx": "^0.16.9",
    "zone.js": "^0.11.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1100.3",
    "@angular/compiler-cli": "^11.0.3",
    "@compodoc/compodoc": "^1.1.11",
    "@types/chart.js": "^2.9.28",
    "@types/jasmine": "3.6.2",
    "@types/node": "^14.14.10",
    "@types/source-map": "^0.5.7",
    "@types/webpack": "^4.41.25",
    "typescript": "~4.0.0"
  }

已尝试无效操作

npm cache clean --force
npm install
npm start

解决思路

1. 适配OpenSSL算法兼容问题

Node.js 14+搭配旧版Webpack(项目使用的@angular-devkit/build-angular@0.1100.3对应Webpack 4)时,会出现OpenSSL算法不兼容导致进程终止的问题,可通过添加环境变量解决:

  • Windows命令提示符:
    set NODE_OPTIONS=--openssl-legacy-provider && npm start
    
  • Linux/macOS终端:
    NODE_OPTIONS=--openssl-legacy-provider npm start
    
    也可以将配置写入package.json的scripts中,修改start命令:
    "scripts": {
      "start": "NODE_OPTIONS=--openssl-legacy-provider ng serve",
      // 保留其他原有命令
    }
    

2. 彻底清理依赖后重装

之前的安装可能存在缓存或依赖损坏,执行以下步骤:

# Linux/macOS
rm -rf node_modules package-lock.json
npm cache clean --force
npm install

# Windows
rmdir /s /q node_modules && del package-lock.json
npm cache clean --force
npm install

3. 检查并锁定TypeScript版本

Angular 11要求TypeScript版本在4.0.x~4.1.x区间,当前项目配置~4.0.0符合要求,但可尝试锁定具体版本(如4.0.7),修改package.json中typescript的版本后重新执行npm install。

4. 查看详细错误日志

执行ng serve --verbose获取完整错误堆栈,定位具体失败模块或配置问题,比如缺失依赖、配置错误等。

5. 匹配Angular CLI版本

确保全局或本地Angular CLI版本与项目Angular 11.x匹配:

# 查看当前版本
ng version

# 安装对应版本CLI
npm install -g @angular/cli@11.0.3

内容的提问来源于stack exchange,提问作者Sinlog

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 16:15:51