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

Angular CLI无法创建组件:执行命令报NullLogger未定义错误

Hey there, sorry you're hitting this annoying error when trying to generate a component with Angular CLI. Let's break down what's causing this and how to fix it step by step:

Fixing "Cannot read property 'NullLogger' of undefined" in Angular CLI

This error typically stems from mismatched Angular CLI versions (global vs local), corrupted dependencies, or a messed-up CLI cache. Here are the most reliable fixes to get you back on track:

1. Sync up global and local Angular CLI versions

Version mismatches are the #1 culprit for this kind of weird runtime error. Let's align everything:

  • First, uninstall the outdated global CLI:
    npm uninstall -g @angular/cli
    
  • Clear out any corrupted cache files:
    npm cache clean --force
    
  • Reinstall the latest stable global CLI:
    npm install -g @angular/cli@latest
    
  • Now update the local CLI package in your project directory:
    npm install @angular/cli@latest --save-dev
    
  • Run the update schematic to sync all related Angular packages:
    ng update @angular/cli @angular/core
    

2. Do a clean reinstall of dependencies

Corrupted node_modules or lock files can also trigger this error. Let's start fresh:

  • Delete the node_modules folder from your project root.
  • Delete package-lock.json (or yarn.lock if you use Yarn).
  • Reinstall all dependencies:
    npm install
    
  • Try generating your component again:
    ng generate component your-component-name
    

3. Clear the Angular CLI cache

Sometimes the CLI's local cache gets corrupted. Wipe it with:

ng cache clean --force

Then retry your component generation command.

4. Verify Node.js compatibility

Make sure your Node.js version plays nice with your Angular version. As a general rule:

  • Angular 15+ requires Node.js 16.14 or later
  • Older Angular versions have specific supported Node ranges (double-check if you're on an older project)
    Check your current Node version with:
node -v

Update Node.js to a compatible version if needed.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:06:56