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

使用Angular CLI 14生成组件报错:tree.actions.filter(...).map(...).at不是函数

解决方案:tree.actions.filter(...).map(...).at is not a function 报错

这个报错的核心原因是你的Node.js版本过低,不支持ES2022引入的Array.at()方法——Angular CLI的新版本会依赖这个API,而旧版Node(低于v14.17.0或v16.6.0)没有实现该方法,导致执行生成命令时抛出错误。重装CLI无法解决这个问题,因为根源在Node环境,而非CLI本身。

具体解决步骤:

  • 先检查当前Node版本:
    node -v
    
  • 升级Node.js到符合你Angular CLI版本的要求:
    • 参考Angular官方版本对应关系:Angular 16+要求Node 16.14.0+,Angular 17+要求Node 18.13.0+
    • 推荐用nvm(Node版本管理器)升级,避免系统权限问题:
      1. 安装nvm后,执行以下命令安装目标版本(以18.x为例):
        nvm install 18
        
      2. 切换到新安装的版本:
        nvm use 18
        
      3. 设置为默认版本(可选,避免每次打开终端切换):
        nvm alias default 18
        
  • 验证升级成功后,重新执行组件生成命令:
    ng generate component test --skip-import
    # 或指定模块的命令
    ng generate component test -m app.module.ts
    
  • 如果升级后仍有问题,清理缓存并重装依赖:
    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 00:02:10