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

ng命令报错求助:无法在angular-cli项目内使用new命令

Fix for "You cannot use the new command inside an angular-cli project" Error

Let’s work through this frustrating issue—even after deleting old projects and config files, Angular CLI might still be picking up leftover traces somewhere. Here’s what you can try step by step:

  • Double-check your current working directory
    Open your terminal and run pwd (Mac/Linux) or cd (Windows) to confirm where you’re trying to create the new project. The CLI checks not just your current folder, but all parent directories for Angular config files. Make sure you’re in a completely fresh directory that has never been part of an Angular project (e.g., your Desktop or a brand-new folder you just created).

  • Hunt for hidden/residual config files
    Sometimes accidental leftover files (even empty ones) can trigger this error. Use ls -la (Mac/Linux) or dir /a (Windows) to show hidden files in your current and parent directories. Look for angular.json, .angular-cli.json, or even a stray package.json that references Angular—delete any of these if they’re in directories where you don’t want an Angular project.

  • Clear CLI cache and reinstall global CLI
    If the above doesn’t work, the CLI’s cache might be stuck. Run these commands in order:

    npm cache clean --force
    npm uninstall -g @angular/cli
    npm install -g @angular/cli
    

    If you use Yarn instead, swap out the npm commands with yarn cache clean, yarn global remove @angular/cli, and yarn global add @angular/cli.

  • Create the project with an absolute path
    To bypass any path detection issues, specify the full absolute path when creating your new project. For example:

    # Mac/Linux
    ng new /Users/your-username/Desktop/fresh-angular-project
    # Windows
    ng new C:\Users\your-username\Desktop\fresh-angular-project
    

    This forces the CLI to initialize the project in a completely isolated, clean directory.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:24:11