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

执行ng generate NgRx store命令时出现ts.getDecorators is not a function错误

问题

执行命令:

ng generate @ngrx/schematics:store AppState --root --module app.module.ts

时触发错误:ts.getDecorators is not a function

解决方法

这个问题核心是TypeScript版本与NgRx Schematics版本不兼容——TypeScript 5.0+移除了ts.getDecorators API,改用ts.decorators,而旧版NgRx Schematics还在调用旧API。

  • 方法1:降级TypeScript到兼容版本
    查看你当前NgRx版本对应的TS支持范围(比如NgRx 15/16适配TS 4.8-4.9),执行命令降级:

    npm install typescript@~4.9.0 --save-dev
    
  • 方法2:升级NgRx到支持TS 5.x的版本
    如果想保留高版本TS,直接升级NgRx相关包到最新版(NgRx 17+已适配TS 5.x):

    npm install @ngrx/store@latest @ngrx/schematics@latest --save
    
  • 方法3:临时修改Schematics代码(应急用,不推荐长期使用)
    找到node_modules/@ngrx/schematics目录下所有调用ts.getDecorators的文件,将其替换为ts.decorators,保存后重新执行生成命令。

内容的提问来源于stack exchange,提问作者sp-sathish

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 14:55:26