ng命令报错求助:无法在angular-cli项目内使用new命令
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 runpwd(Mac/Linux) orcd(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. Usels -la(Mac/Linux) ordir /a(Windows) to show hidden files in your current and parent directories. Look forangular.json,.angular-cli.json, or even a straypackage.jsonthat 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/cliIf you use Yarn instead, swap out the npm commands with
yarn cache clean,yarn global remove @angular/cli, andyarn 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-projectThis forces the CLI to initialize the project in a completely isolated, clean directory.
内容的提问来源于stack exchange,提问作者Ramanand Prajapati

