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

使用VS Angular+ASP.NET模板新建项目时遇Unexpected end of input错误求助

Angular+ASP.NET模板项目npm启动失败:Unexpected end of input 解决方法

问题场景

使用Visual Studio的Angular搭配ASP.NET模板创建全新项目后,首次构建出现以下错误:

An unhandled exception occurred: Unexpected end of input
See "/private/var/folders/kd/060hv6cj1j10wddm4h7sc50r0000gn/T/ng-BFqD9a/angular-errors.log" for further details.
fail: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      Couldn't start the SPA development server with command 'npm start'.
Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager: Error: Couldn't start the SPA development server with command 'npm start'.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      No SPA development server running at https://localhost:44487 found.
  PID   TT  STAT      TIME COMMAND
84889   ??  S      0:00.82 /usr/local/share/dotnet/dotnet /Users/jacklohse/repos/AidanBoard/AidanBoard/bin/Debug/net7.0/AidanBoard.dll
info: Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware[0]
      SPA proxy is not ready. Returning temporary landing page.

查看angular-errors.log,核心错误为:

[error] SyntaxError: Unexpected end of input
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)

更换Node.js LTS及最新版本均无法解决,Visual Studio和命令行执行npm start均失败。

解决步骤

  • 检查package.json语法完整性
    该错误绝大多数由JSON文件格式损坏导致。找到项目中Angular部分的package.json(通常在ClientApp目录下),排查以下问题:

    • 最后一个依赖项/脚本后是否多了多余逗号
    • 引号、大括号是否正确闭合
      可在该目录下执行命令快速验证:
    node -e "require('./package.json')"
    

    命令会直接提示语法错误位置,修复后重新尝试启动。

  • 清理依赖缓存并重装
    进入Angular项目根目录(ClientApp),执行以下命令:

    rm -rf node_modules
    rm package-lock.json
    npm cache clean --force
    npm install
    

    完成后运行npm start测试。

  • 使用本地Angular CLI启动
    全局Angular CLI版本可能与模板依赖版本不兼容,尝试用项目本地CLI启动:

    npx ng serve
    

    若成功,说明全局版本存在冲突,可将本地CLI版本同步到全局,或修改项目package.json的start脚本为ng serve(确保本地CLI已安装)。

  • 重新创建项目验证文件完整性
    若以上步骤无效,可能是新建项目时文件下载不完整。重新创建同模板项目,对比两个项目的配置文件(如angular.json、tsconfig.json、package.json),将缺失或损坏的文件替换到原项目中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 04:03:45