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

添加@angular/pwa遇Schema验证及终端检测报错求助

解决Angular添加PWA的两类报错

第一类报错:Schema验证不通过(legacyPeerDeps)

执行以下命令时触发错误:

ng add @angular/pwa
ng add @angular/pwa@17.1.0 --legacy-peer-deps
ng add @angular/pwa@17.1.2 --legacy-peer-deps

错误信息:

Schematic input does not validate against the Schema: {"legacyPeerDeps":true,"project":"sitemap-web-app","target":"build"}
Errors:
  Data path "" must NOT have additional properties(legacyPeerDeps).

原因

--legacy-peer-deps是npm专属的安装参数,并非Angular Schematics(ng add执行的脚手架逻辑)支持的输入项,直接附加到ng add命令会被误判为schematics参数,导致Schema验证失败。

解决方案

分两步操作,先单独用npm安装包,再手动运行初始化逻辑:

  1. 安装@angular/pwa包(带上npm的legacy参数):
npm install @angular/pwa@17.1.2 --legacy-peer-deps --save-dev
  1. 运行PWA初始化的schematics(替换project值为你的项目名,即package.json里的web-app):
ng generate @angular/pwa:ng-add --project=web-app

第二类报错:终端检测失败(No terminal detected)

更新全局Angular CLI到17.1.2、重装依赖后,执行ng add @angular/pwa出现:

No terminal detected. '--skip-confirmation' can be used to bypass installation confirmation. Ensure package name is correct prior to '--skip-confirmation' option usage.
Command aborted.

原因

当前终端环境无法提供交互式确认的能力,ng add需要用户确认安装操作,但检测不到终端交互支持,因此终止命令。

解决方案

添加--skip-confirmation参数直接跳过确认步骤:

ng add @angular/pwa --skip-confirmation

如果仍存在依赖冲突,可结合第一类问题的解决思路,临时开启npm的legacy peer deps配置后再执行命令:

npm config set legacy-peer-deps true
ng add @angular/pwa --skip-confirmation
# 安装完成后可按需恢复默认配置
npm config set legacy-peer-deps false

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 02:45:02