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

Windows 10下Angular CLI安装后运行报错的修复方法

Angular CLI运行报错:Unexpected token ) 问题排查与解决

问题场景

Windows 10环境,安装Node.js v20后执行npm install -g @angular/cli@17安装Angular CLI,运行ng命令时触发语法错误:

C:\Users\Work\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng.js:20
);
^
SyntaxError: Unexpected token )

查看报错文件第20行代码:

console.error(
'This is the external Angular CLI, but you appear to be running in google3. There is a separate, internal version of the CLI which should be used instead. See http://go/angular/cli.',
);

尝试切换Node.js v18搭配Angular CLI v16,仍出现相同错误。

问题根源

报错代码中的提示明确指向google3环境,说明你安装的不是官方公开的Angular CLI版本,而是Google内部定制的CLI包。大概率是你的npm registry被设置为Google内部源,导致下载了内部定制版而非官方包,多余逗号只是内部版本未转译的语法问题,核心原因是包来源错误。

解决步骤

  • 检查当前npm源:执行npm config get registry,确认是否为官方源(https://registry.npmjs.org/)
  • 切换到官方npm源:如果当前源不是官方源,执行npm config set registry https://registry.npmjs.org/
  • 卸载错误的CLI:执行npm uninstall -g @angular/cli,同时手动删除残留目录C:\Users\Work\AppData\Roaming\npm\node_modules\@angular
  • 重新安装官方CLI:执行npm install -g @angular/cli@17(按需指定版本)
  • 验证安装:执行ng version,正常输出版本信息即为修复成功

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 08:43:13