升级Angular 6遇npm报错:Refusing to delete,求解决方案
Hey there, let's tackle that frustrating error you're running into while upgrading your Angular 5.2 app to Angular 6. That Refusing to delete... message happens because the ng executable in your project's node_modules/.bin directory isn't managed by the new @angular/cli package you're trying to install—probably a leftover from an older CLI version or a misaligned global/local install.
Here's a step-by-step fix:
First, remove the conflicting file
Depending on your operating system, run the appropriate command:- For macOS/Linux:
rm [MyProjectDirectory]/node_modules/.bin/ng - For Windows (Command Prompt):
del [MyProjectDirectory]\node_modules\.bin\ng
- For macOS/Linux:
Clear the npm cache to avoid residual issues
npm cache clean --forceReinstall the project-level Angular CLI
Now go back to your project directory and run:npm install @angular/cliContinue with the official upgrade steps
Once the CLI installs successfully, proceed with the update command:ng update @angular/cliThen upgrade the Angular core packages to version 6:
ng update @angular/core
If you still run into issues:
If the problem persists, try a full clean reinstall to eliminate any corrupted dependencies:
- Delete the
node_modulesfolder andpackage-lock.jsonfile:- macOS/Linux:
rm -rf node_modules package-lock.json - Windows:
rmdir /s /q node_modules del package-lock.json
- macOS/Linux:
- Reinstall all dependencies:
npm install - Then repeat the CLI install and update steps above.
That should get you past the file conflict and back on track with your upgrade.
内容的提问来源于stack exchange,提问作者MikeP

